| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package KiokuDB::Test::Fixture; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Test::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | sub _lives_and_ret (&;$) { | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 2201 | ▶ | my ( $sub, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lives_and_ret: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2201 | my @ret; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 2201 | my $wrapped = sub { @ret = $sub->() }; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2201 | local $Test::Builder::Level = $Test::Builder::Level + 2; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 2201 | &lives_ok($wrapped, @args); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2201 | ▶ | return ( ( @ret == 1 ) ? $ret[0] : @ret ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | requires qw(create verify); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 102 | ▶ | sub sort { 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 231 | ▶ | sub required_backend_roles { return () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
required_backend_roles: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | has populate_ids => ( | |||||||||||||||||||||||||||||||||||||||||
| 30 | isa => "ArrayRef[Str]", | ||||||||||||||||||||||||||||||||||||||||||
| 31 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 32 | predicate => "has_populate_ids", | ||||||||||||||||||||||||||||||||||||||||||
| 33 | clearer => "clear_populate_ids", | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | sub populate { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 314 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
populate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 314 | my $s = $self->new_scope; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 314 | my @objects = $self->create; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 314 | my @ids = $self->store_ok(@objects); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 314 | $self->populate_ids(\@ids); | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 314 | $self->no_live_objects; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | sub name { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 2001 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2001 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2001 | $class =~ s{KiokuDB::Test::Fixture::}{}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 2001 | return $class; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub skip_fixture { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 81 | ▶ | my ( $self, $reason, $count ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skip_fixture: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 81 | ▶ | skip $self->name . " fixture ($reason)", $count || 1 | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$count || 1
MC/DC0%0/1
$count || 1
$count
Truth table50%1/2
A
A= $count
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | sub precheck { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 561 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
precheck: called CC=12 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 561 | my $backend = $self->backend; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 561 | ▶ | if ( $backend->does("KiokuDB::Backend::Role::Broken") ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | foreach my $fixture ( $backend->skip_fixtures ) { | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $self->skip_fixture("broken backend") if $fixture eq ref($self) or $fixture eq $self->name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fixture eq ref $self or $fixture eq $self->name
MC/DC0%0/2
$fixture eq ref $self or $fixture eq $self->name
$fixture eq ref $self
$fixture eq $self->name
Truth table0%0/3
A or B
A= $fixture eq ref $selfB= $fixture eq $self->name
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 561 | my @missing; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 561 | role: foreach my $role ( $self->required_backend_roles ) { | |||||||||||||||||||||||||||||||||||||||||
| 79 | 561 | foreach my $role_fmt ( $role, "KiokuDB::Backend::Role::$role", "KiokuDB::Backend::$role" ) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1236 | ▶ | next role if $backend->does($role_fmt) or $backend->can("serializer") and $backend->serializer->does($role_fmt); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$backend->does($role_fmt) or $backend->can("serializer") and $backend->serializer->does($role_fmt)
$backend->can("serializer") and $backend->serializer->does($role_fmt)
MC/DC66%2/3
$backend->does($role_fmt) or $backend->can("serializer") and $backend->serializer->does($role_fmt)
$backend->does($role_fmt)
$backend->can("serializer")
$backend->serializer->does($role_fmt)
Truth table75%3/4
A or B and C
A= $backend->does($role_fmt)B= $backend->can("serializer")C= $backend->serializer->does($role_fmt)
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 81 | push @missing, $role; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 561 | ▶ | if ( @missing ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 81 | $_ =~ s/^KiokuDB::Backend::Role::// for @missing; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 81 | $self->skip_fixture("Backend does not implement required roles (@missing)") | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | sub run { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 561 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 561 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 561 | $self->precheck; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 480 | $self->clear_live_objects; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 480 | is_deeply( [ $self->live_objects ], [ ], "no live objects at start of " . $self->name . " fixture" ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 480 | is_deeply( [ $self->live_entries ], [ ], "no live entries at start of " . $self->name . " fixture" ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | lives_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 480 | ▶ | local $Test::Builder::Level = $Test::Builder::Level - 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | $self->txn_do(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 480 | ▶ | my $s = $self->new_scope; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 480 | $self->populate; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 480 | }); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 480 | $self->verify; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 480 | } "no error in fixture"; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 480 | is_deeply( [ $self->live_objects ], [ ], "no live objects at end of " . $self->name . " fixture" ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 480 | is_deeply( [ $self->live_entries ], [ ], "no live entries at end of " . $self->name . " fixture" ); | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 480 | $self->clear_live_objects; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | has get_directory => ( | |||||||||||||||||||||||||||||||||||||||||
| 121 | isa => "CodeRef|Str", | ||||||||||||||||||||||||||||||||||||||||||
| 122 | is => "ro", | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | has directory => ( | |||||||||||||||||||||||||||||||||||||||||
| 126 | is => "ro", | ||||||||||||||||||||||||||||||||||||||||||
| 127 | isa => "KiokuDB", | ||||||||||||||||||||||||||||||||||||||||||
| 128 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | handles => [qw( | ||||||||||||||||||||||||||||||||||||||||||
| 130 | lookup exists | ||||||||||||||||||||||||||||||||||||||||||
| 131 | store | ||||||||||||||||||||||||||||||||||||||||||
| 132 | insert update delete | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | clear_live_objects | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | backend | ||||||||||||||||||||||||||||||||||||||||||
| 137 | linker | ||||||||||||||||||||||||||||||||||||||||||
| 138 | collapser | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | search | ||||||||||||||||||||||||||||||||||||||||||
| 141 | simple_search | ||||||||||||||||||||||||||||||||||||||||||
| 142 | backend_search | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | is_root | ||||||||||||||||||||||||||||||||||||||||||
| 145 | set_root | ||||||||||||||||||||||||||||||||||||||||||
| 146 | unset_root | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | all_objects | ||||||||||||||||||||||||||||||||||||||||||
| 149 | root_set | ||||||||||||||||||||||||||||||||||||||||||
| 150 | scan | ||||||||||||||||||||||||||||||||||||||||||
| 151 | grep | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | new_scope | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | txn_do | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | object_to_id | ||||||||||||||||||||||||||||||||||||||||||
| 158 | objects_to_ids | ||||||||||||||||||||||||||||||||||||||||||
| 159 | )], | ||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | sub _build_directory { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 561 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_directory: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 561 | ▶ | my $method = $self->get_directory or die "either 'directory' or 'get_directory' is required"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 561 | return $self->$method; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | sub live_objects { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | shift->directory->live_objects->live_objects | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 2821 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
live_objects: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | sub live_entries { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | shift->directory->live_objects->live_entries | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 960 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
live_entries: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | sub update_live_objects { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 26 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_live_objects: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 26 | ▶ | _lives_and_ret { $self->update( $self->live_objects ) } "updated live objects"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | sub store_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 506 | ▶ | my ( $self, @objects ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
store_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 506 | local $Test::Builder::Level = 1; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 506 | ▶ | _lives_and_ret { $self->store( @objects ) } "stored " . scalar(grep { ref } @objects) . " objects"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | sub update_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 356 | ▶ | my ( $self, @objects ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 356 | ▶ | _lives_and_ret { $self->update( @objects ) } "updated " . scalar(@objects) . " objects"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | sub insert_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 174 | ▶ | my ( $self, @objects ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 174 | ▶ | _lives_and_ret { $self->insert( @objects ) } "inserted " . scalar(@objects) . " objects"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | sub delete_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 134 | ▶ | my ( $self, @objects ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 134 | ▶ | _lives_and_ret { $self->delete( @objects ) } "deleted " . scalar(@objects) . " objects"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | sub lookup_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 1005 | ▶ | my ( $self, @ids ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup_ok: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1005 | my @ret; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 1005 | ▶ | _lives_and_ret { @ret = $self->lookup( @ids ) } "lookup " . scalar(@ids) . " objects"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 1005 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 1005 | is( scalar(grep { ref } @ret), scalar(@ids), "all lookups succeeded" ); | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1005 | ▶ | return ( ( @ret == 1 ) ? $ret[0] : @ret ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | sub exists_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 133 | ▶ | my ( $self, @ids ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 133 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 133 | is( scalar(grep { $_ } $self->exists(@ids)), scalar(@ids), "[@ids] exist in DB" ); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | sub root_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 207 | ▶ | my ( $self, @objects ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 207 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 207 | is( scalar(grep { $_ } $self->is_root(@objects)), scalar(@objects), "[@{[ $self->objects_to_ids(@objects) ]}] are in the root set" ); | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | sub not_root_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 275 | ▶ | my ( $self, @objects ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
not_root_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 275 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 275 | is( scalar(grep { not $_ } $self->is_root(@objects)), scalar(@objects), "[@{[ $self->objects_to_ids(@objects) ]}] aren't in the root set" ); | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | sub deleted_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 218 | ▶ | my ( $self, @ids ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleted_ok: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 218 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 218 | is( scalar(grep { !$_ } $self->exists(@ids)), scalar(@ids), "@ids do not exist in DB" ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | sub lookup_obj_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 204 | ▶ | my ( $self, $id, $class ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup_obj_ok: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 204 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 204 | ok( my $obj = $self->lookup($id), "lookup $id" ); | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 156 | ▶ | isa_ok( $obj, $class ) if $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 156 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | sub no_live_objects { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 1592 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
no_live_objects: called CC=6 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 1592 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1592 | my $fail; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 1592 | my @l = $self->live_objects; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 1592 | my @e; | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | my $failed; | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 1592 | ▶ | $failed++ unless is( scalar(@l), 0, "no live objects" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 1592 | ▶ | unless ( $self->directory->live_objects->txn_scope ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | # no live objects should imply no live entries | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # however, under keep_entries a txn stack is maintained | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 1361 | ▶ | $failed++ unless is( scalar(@e), 0, "no live entries" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 1361 | @e = $self->directory->live_objects->live_entries; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 1592 | ▶ | if ( $failed ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | diag "live objects: " . join ", ", map { $self->object_to_id($_) . " ($_)" } @l if @l; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | diag "live entries: " . join ", ", map { $_->id . " (" . $_->class . ")" } @e; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | #use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||||||||||
| 292 | #weaken($_) for @l; | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $self->directory->live_objects->clear; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | #use Devel::FindRef; | ||||||||||||||||||||||||||||||||||||||||||
| 297 | #my $track = Devel::FindRef::track(@l); | ||||||||||||||||||||||||||||||||||||||||||
| 298 | #warn $track; | ||||||||||||||||||||||||||||||||||||||||||
| 299 | #my ( @ids ) = map { hex } ( $track =~ /by \w+\(0x([a-z0-9]+)\)/ ); | ||||||||||||||||||||||||||||||||||||||||||
| 300 | #warn Data::Dumper::Dumper(map { Devel::FindRef::ptr2ref($_) } @ids); | ||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | sub no_live_entries { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
no_live_entries: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my @e = $self->directory->live_objects->live_entries; | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | unless ( is( scalar(@e), 0, "no live entries" ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | diag "live entries: " . join ", ", map { $_->id . " (" . $_->class . ")" } @e; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $self->directory->live_objects->clear; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | sub live_objects_are { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 217 | ▶ | my ( $self, @objects ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
live_objects_are: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 217 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 217 | is_deeply( [ sort $self->live_objects ], [ sort @objects ], "correct live objects" ); | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | sub txn_lives { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 1147 | ▶ | my ( $self, $code, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_lives: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | lives_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 330 | $self->txn_do(sub { | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 1147 | ▶ | my $s = $self->new_scope; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 1147 | $code->(@_); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 1147 | ▶ | }, @args); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 1147 | } "transaction finished without errors"; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 4 | __PACKAGE__ | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | __END__ | ||||||||||||||||||||||||||||||||||||||||||