File Coverage

blib/lib/KiokuDB/Test/Fixture/Small.pm
Criterion Covered Total %
statement 59 59 100.0
branch n/a
condition n/a
subroutine 13 13 100.0
pod 0 4 0.0
total 72 76 94.7


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuDB::Test::Fixture::Small;
4 2     2   1511 use Moose;
  2         2  
  2         58  
5              
6 2     2   9601 use Test::More;
  2         4  
  2         17  
7 2     2   512 use Test::Exception;
  2         4  
  2         14  
8              
9 2     2   364 use Scalar::Util qw(refaddr);
  2         4  
  2         104  
10              
11 2     2   9 use KiokuDB::Test::Person;
  2         4  
  2         39  
12 2     2   8 use KiokuDB::Test::Employee;
  2         2  
  2         30  
13 2     2   7 use KiokuDB::Test::Company;
  2         3  
  2         57  
14              
15             sub p;
16              
17 2     2   8 use namespace::clean -except => 'meta';
  2         5  
  2         17  
18              
19             sub p {
20             my @args = @_;
21             unshift @args, "name" if @args % 2;
22             KiokuDB::Test::Person->new(@args);
23             }
24              
25             with qw(KiokuDB::Test::Fixture) => { excludes => [qw/populate sort/] };
26              
27 22     22 0 50 sub sort { -100 }
28              
29             has [qw(joe oscar)] => (
30             isa => "Str",
31             is => "rw",
32             );
33              
34             sub create {
35             return (
36 67     67 0 2142 KiokuDB::Test::Employee->new(
37             name => "joe",
38             age => 52,
39             parents => [ KiokuDB::Test::Person->new(
40             name => "mum",
41             age => 78,
42             ) ],
43             company => KiokuDB::Test::Company->new(
44             name => "OHSOME SOFTWARE KTHX"
45             ),
46             ),
47             KiokuDB::Test::Person->new(
48             name => "oscar",
49             age => 3,
50             ),
51             );
52             }
53              
54             sub populate {
55 67     67 0 143 my $self = shift;
56              
57             {
58 67         98 my $s = $self->new_scope;
  67         259  
59              
60 67         433 my ( $joe, $oscar ) = $self->create;
61              
62 67         319 isa_ok( $joe, "KiokuDB::Test::Person" );
63 67         27315 isa_ok( $joe, "KiokuDB::Test::Employee" );
64              
65 67         23693 isa_ok( $oscar, "KiokuDB::Test::Person" );
66              
67 67         23734 my ( $joe_id, $oscar_id ) = $self->store_ok($joe, $oscar);
68              
69 67         3338 $self->joe($joe_id);
70 67         2439 $self->oscar($oscar_id);
71              
72 67         2066 $self->live_objects_are($joe, $joe->company, @{ $joe->parents }, $oscar);
  67         2124  
73             }
74              
75 67         2175 $self->no_live_objects;
76             }
77              
78             sub verify {
79 33     33 0 84 my $self = shift;
80              
81             $self->txn_lives(sub {
82 33     33   1000 my ( $joe, $oscar ) = my @objs = $self->lookup_ok( $self->joe, $self->oscar );
83              
84 33         189 isa_ok( $joe, "KiokuDB::Test::Person" );
85 33         12160 isa_ok( $joe, "KiokuDB::Test::Employee" );
86              
87 33         11450 isa_ok( $oscar, "KiokuDB::Test::Person" );
88              
89 33         13198 my $entry = $self->directory->live_objects->object_to_entry($joe);
90              
91 33         941 ok( $entry->has_object, "entry is associated with object" );
92              
93 33         11173 is( refaddr($entry->object), refaddr($joe), "the right object" );
94              
95 33         11812 is( $joe->name, "joe", "name" );
96              
97 33         11114 ok( my $parents = $joe->parents, "parents" );
98              
99 33         10141 is( ref($parents), "ARRAY", "array ref" );
100              
101 33         10035 is( scalar(@$parents), 1, "one parent" );
102              
103 33         9951 isa_ok( $parents->[0], "KiokuDB::Test::Person" );
104              
105 33         12089 is( $parents->[0]->name, "mum", "parent name" );
106              
107 33         10982 ok( my $company = $joe->company, "company" );
108              
109 33         9856 isa_ok( $company, "KiokuDB::Test::Company" );
110              
111 33         12411 is( $oscar->name, "oscar", "name" );
112              
113 33         10188 lives_ok { $self->directory->lookup("no_such_id") } "lookup of nonexistent ID is nonfatal";
  33         2234  
114 33         355 });
115             }
116             __PACKAGE__
117              
118             __END__