File: hello-tangram.pl

package info (click to toggle)
libtangram-perl 2.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,304 kB
  • sloc: perl: 10,260; makefile: 9
file content (40 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
#
# the missing bare bones example, from Sebastian Riedel.
#

use DBI;
use Tangram;
use Class::Tangram::Generator;

my $schema = Tangram::Schema->new(
    {
        classes => [
            Orange => {
                fields  => { int => [qw(juicyness ripeness)] },
                methods => {
                    squeeze => sub {
                        my $self = shift;
                        $self->juicyness( $self->juicyness() - 1 );
                    },
                    eviscerate => sub {
                        my $self = shift;
                        $self->juicyness(0);
                    },
                }
            }
        ]
    }
);

if ( $ARGV[0] ) {
    my $dbh = DBI->connect('dbi:SQLite:test.db');
    Tangram::Relational->deploy( $schema, $dbh );
}

my $gen     = Class::Tangram::Generator->new($schema);
my $storage = Tangram::Relational->connect( $schema, 'dbi:SQLite:test.db' );

my $orange = $gen->new('Orange');
$orange->juicyness(20);
$storage->insert($orange);