KiokuDB/Test/Fixture/TypeMap/Default.pm

filter: Statementstmt 78.7% 174 / 221 Branchbran 44.1% 15 / 34 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 94.7% 36 / 38 Podpod 0.0% 0 / 3 totaltotal 72.8% 225 / 309 CC 19 SCAR 20.1
CC
19
Cov
72%
verify
22.0
create
14.7
a_role_method
2.0
CRAP 7.5
« KiokuDB/TypeMap/Entry/StorableHook.pm ↑ Summary KiokuDB/Thunk.pm »
1 #!/usr/bin/perl
2  
3 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package KiokuDB::Test::Fixture::TypeMap::Default;
6 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Test::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use KiokuDB::Test::Person;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use KiokuDB::Test::Employee;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use KiokuDB::Test::Company;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use constant required_backend_roles => qw(TypeMap::Default);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use Tie::RefHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use constant HAVE_DATETIME => try { require DateTime };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
23 2 ▶use constant HAVE_DATETIME_FMT => try { require DateTime::Format::Strptime };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
24 2 ▶use constant HAVE_URI => try { require URI };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
25 2 ▶use constant HAVE_URI_WITH_BASE => try { require URI::WithBase };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
26 2 ▶use constant HAVE_AUTHEN_PASSPHRASE => try { require Authen::Passphrase::SaltedDigest };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
27 2 ▶use constant HAVE_PATH_CLASS => try { require Path::Class };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 ▶use constant HAVE_IXHASH => try { require Tie::IxHash };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
29 2 ▶use constant HAVE_MX_TRAITS => try { require MooseX::Traits };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
30 2 ▶use constant HAVE_MX_OP => try { require MooseX::Object::Pluggable };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
31  
32 {
33 2 package Some::Role;
34 2 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 has role_attr => ( is => "rw" );
37  
38 package Some::Other::Role;
39 2 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 2 has other_role_attr => ( is => "rw" );
42  
43 package Some::Third::Role;
44 2 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 0 ▶ sub a_role_method { "hello" }
Subroutine a_role_method: not called CC=1 SCAR=6.9
Pod undocumented
47  
48 package Some::Class;
49 2 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 2 ▶ if ( KiokuDB::Test::Fixture::TypeMap::Default::HAVE_MX_TRAITS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&KiokuDB::Test::Fixture::TypeMap::Default::HAVE_MX_TRAITS()) 0 2 2
52 0 with qw(MooseX::Traits);
53 }
54  
55 2 ▶ if ( KiokuDB::Test::Fixture::TypeMap::Default::HAVE_MX_OP ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&KiokuDB::Test::Fixture::TypeMap::Default::HAVE_MX_OP()) 0 2 2
56 0 with qw(MooseX::Object::Pluggable);
57 }
58  
59 2 has name => ( is => "rw" );
60 }
61  
62 2 with qw(KiokuDB::Test::Fixture) => { excludes => 'required_backend_roles' };
63  
64 sub create {
65 33 ▶ tie my %refhash, 'Tie::RefHash';
Subroutine create: called CC=8 SCAR=26.9
Pod undocumented
66  
67 33 $refhash{["foo"]} = "bar";
68  
69 33 $refhash{"blah"} = "oink";
70  
71 33 my %ixhash;
72 33 ▶ tie %ixhash, 'Tie::IxHash' if HAVE_IXHASH;
Branch: 1 branch
BranchTrueFalseTotal
if &HAVE_IXHASH() 0 33 33
73 33 %ixhash = ( first => 1, second => "yes", third => "maybe", fourth => "a charm" );
74  
75 33 my $homer = KiokuDB::Test::Employee->new(
76 name => "Homer Simpson",
77 company => KiokuDB::Test::Company->new(
78 name => "Springfield Power Plant",
79 ),
80 );
81  
82 33 Some::Role->meta->apply($homer);
83  
84 33 $homer->role_attr("foo");
85  
86 33 my $foo = "blah";
87  
88 33 my @x = ( 1 );
89  
90 return (
91 scalar => \$foo,
92 refhash => \%refhash,
93 0 ▶ coderef => sub { $x[0]++; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 HAVE_IXHASH ? ( ixhash => \%ixhash ) : (),
95 HAVE_DATETIME ? ( datetime => { obj => DateTime->now } ) : (),
96 HAVE_DATETIME_FMT ? ( datetime_fmt => { obj => DateTime->now(formatter => DateTime::Format::Strptime->new( pattern => '%F' ) ) } ) : (),
97 HAVE_PATH_CLASS ? ( path_class => { obj => Path::Class::file('bar', 'foo.txt') } ) : (),
98 HAVE_URI ? ( uri => { obj => URI->new('http://www.google.com/') } ) : (),
99 HAVE_URI_WITH_BASE ? (
100 with_base => {
101 obj => URI::WithBase->new(
102 URI->new('foo'),
103 URI->new('http://www.google.com/')
104 ),
105 },
106 ) : (),
107 HAVE_AUTHEN_PASSPHRASE ? (
108 passphrase => {
109 obj => Authen::Passphrase::SaltedDigest->new(
110 algorithm => "SHA-1", salt_random => 20,
111 passphrase => "passphrase"
112 ),
113 },
114 ) : (),
115 HAVE_MX_TRAITS ? (
116 traits => {
117 obj => Some::Class->new_with_traits(
118 traits => [qw(Some::Other::Role Some::Third::Role)],
119 name => "blah",
120 other_role_attr => "foo",
121 ),
122 },
123 ) : (),
124 HAVE_MX_OP ? (
125 op_one => do {
126 0 my $obj = Some::Class->new( name => "first" );
127  
128 0 $obj->load_plugin("+Some::Other::Role");
129  
130 0 $obj->other_role_attr("after");
131  
132 0 $obj;
133 },
134 33 ▶ op_two => do {
Branch: 6 branches
BranchTrueFalseTotal
&HAVE_IXHASH() ? : 0 33 33
&HAVE_DATETIME() ? : 0 33 33
&HAVE_DATETIME_FMT() ? : 0 33 33
&HAVE_AUTHEN_PASSPHRASE() ? : 0 33 33
&HAVE_MX_TRAITS() ? : 0 33 33
&HAVE_MX_OP() ? : 0 33 33
135 0 my $obj = Some::Class->new( name => "second" );
136
137 0 $obj->load_plugin("+Some::Other::Role");
138  
139 0 $obj->other_role_attr("after");
140  
141 0 $obj->load_plugin("+Some::Third::Role");
142  
143 0 $obj;
144 },
145 ) : (),
146 homer => $homer,
147 );
148 }
149  
150 sub verify {
151 33 ▶ my $self = shift;
Subroutine verify: called CC=12 SCAR=30.9
Pod undocumented
152  
153 {
154 33 my $s = $self->new_scope;
155  
156 33 my $scalar = $self->lookup_ok("scalar");
157  
158 33 is( ref($scalar), "SCALAR", "reftype for scalar" );
159  
160 33 is( $$scalar, "blah", "value" );
161 }
162  
163 25 $self->no_live_objects;
164  
165 {
166 25 my $s = $self->new_scope;
167  
168 25 my $rh = $self->lookup_ok("refhash");
169  
170 25 is( ref($rh), "HASH", "plain hash" );
171 25 isa_ok( tied(%$rh), "Tie::RefHash", "tied" );
172  
173 25 ▶ is_deeply( [ sort { ref($a) ? -1 : ( ref($b) ? 1 : ( $a cmp $b ) ) } keys %$rh ], [ ["foo"], "blah" ], "keys" );
Branch: 2 branches
BranchTrueFalseTotal
ref $a ? : 25 0 25
ref $b ? : 0 0 0
174  
175 }
176  
177 25 $self->no_live_objects;
178  
179 {
180 25 my $s = $self->new_scope;
181  
182 25 my $c = $self->lookup_ok("coderef");
183  
184 25 is( ref($c), "CODE", "coderef" );
185  
186 25 is( $c->(), 1, "invoke closure" );
187 25 is( $c->(), 2, "invoke closure" );
188 }
189  
190 25 $self->no_live_objects;
191  
192 {
193 25 my $s = $self->new_scope;
194  
195 25 my $c = $self->lookup_ok("coderef");
196  
197 25 is( ref($c), "CODE", "coderef" );
198  
199 25 is( $c->(), 1, "invoke closure" );
200 25 is( $c->(), 2, "invoke closure" );
201  
202 25 $self->store_ok($c);
203 }
204  
205 25 $self->no_live_objects;
206  
207 {
208 25 my $s = $self->new_scope;
209  
210 25 my $c = $self->lookup_ok("coderef");
211  
212 25 is( ref($c), "CODE", "coderef" );
213  
214 25 is( $c->(), 3, "closure updated" );
215 }
216  
217 25 $self->no_live_objects;
218  
219 {
220 25 my $s = $self->new_scope;
221  
222 25 my $homer = $self->lookup_ok("homer");
223  
224 25 isa_ok( $homer, "KiokuDB::Test::Person" );
225 25 is( $homer->name, "Homer Simpson", "class attr" );
226 25 does_ok( $homer, "Some::Role", "does runtime role" );
227 25 is( $homer->role_attr, "foo", "role attr" );
228 25 ok( $homer->meta->is_anon_class, "anon class" );
229 25 isa_ok( $homer->company, "KiokuDB::Test::Company" );
230  
231 25 undef $homer;
232 }
233  
234 25 ▶ if ( HAVE_IXHASH ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&HAVE_IXHASH()) 0 25 25
235 0 $self->no_live_objects;
236 0 my $s = $self->new_scope;
237  
238 0 my $ix = $self->lookup_ok("ixhash");
239  
240 0 is( ref($ix), "HASH", "plain hash" );
241 0 isa_ok( tied(%$ix), "Tie::IxHash", "tied" );
242  
243 0 is_deeply( [ keys %$ix ], [ qw(first second third fourth) ], "key order preserved" );
244 }
245  
246 25 ▶ if ( HAVE_DATETIME ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&HAVE_DATETIME()) 0 25 25
247 0 $self->no_live_objects;
248 0 my $s = $self->new_scope;
249  
250 0 my $date = $self->lookup_ok("datetime")->{obj};
251  
252 0 isa_ok( $date, "DateTime" );
253 }
254
255 25 ▶ if ( HAVE_DATETIME_FMT ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&HAVE_DATETIME_FMT()) 0 25 25
256 0 $self->no_live_objects;
257 0 my $s = $self->new_scope;
258  
259 0 my $date = $self->lookup_ok("datetime_fmt")->{obj};
260  
261 0 isa_ok( $date, "DateTime" );
262
263 SKIP: {
264 0 ▶ skip "Not possible with JSON atm", 1 if (
Branch: 1 branch
BranchTrueFalseTotal
if $self->directory->backend->can("serializer") and $self->directory->backend->serializer->isa("KiokuDB::Serializer::JSON") or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSON") or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSPON") 0 0 0
Condition0%0/9
$self->directory->backend->can("serializer") and $self->directory->backend->serializer->isa("KiokuDB::Serializer::JSON") or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSON") or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSPON")
l!l&&r!l&&!r
000
$self->directory->backend->can("serializer") and $self->directory->backend->serializer->isa("KiokuDB::Serializer::JSON") or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSON")
l!l&&r!l&&!r
000
$self->directory->backend->can("serializer") and $self->directory->backend->serializer->isa("KiokuDB::Serializer::JSON")
!ll&&!rl&&r
000
MC/DC0%0/4
$self->directory->backend->can("serializer") and $self->directory->backend->serializer->isa("KiokuDB::Serializer::JSON") or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSON") or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSPON")
$self->directory->backend->can("serializer") $self->directory->backend->serializer->isa("KiokuDB::Serializer::JSON") $self->directory->backend->does("KiokuDB::Backend::Serialize::JSON") $self->directory->backend->does("KiokuDB::Backend::Serialize::JSPON")
Truth table0%0/7
A and B or C or D
A= $self->directory->backend->can("serializer")B= $self->directory->backend->serializer->isa("KiokuDB::Serializer::JSON")C= $self->directory->backend->does("KiokuDB::Backend::Serialize::JSON")D= $self->directory->backend->does("KiokuDB::Backend::Serialize::JSPON")
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
265 ( $self->directory->backend->can("serializer")
266 and $self->directory->backend->serializer->isa('KiokuDB::Serializer::JSON') )
267 or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSON")
268 or $self->directory->backend->does("KiokuDB::Backend::Serialize::JSPON")
269 );
270
271 0 isa_ok( $date->formatter, "DateTime::Format::Strptime" );
272 }
273
274 }
275
276  
277 25 if ( HAVE_URI ) {
278 25 $self->no_live_objects;
279 25 my $s = $self->new_scope;
280  
281 25 my $uri = $self->lookup_ok("uri")->{obj};
282  
283 25 isa_ok( $uri, "URI" );
284 25 is( "$uri", "http://www.google.com/", "uri" );
285 }
286  
287 25 if ( HAVE_URI_WITH_BASE ) {
288 25 $self->no_live_objects;
289 25 my $s = $self->new_scope;
290  
291 25 my $uri = $self->lookup_ok("with_base")->{obj};
292  
293 25 isa_ok( $uri, "URI::WithBase" );
294  
295 25 isa_ok( $uri->base, "URI" );
296 }
297  
298 25 if ( HAVE_PATH_CLASS ) {
299 25 $self->no_live_objects;
300 25 my $s = $self->new_scope;
301  
302 25 my $file = $self->lookup_ok("path_class")->{obj};
303  
304 25 isa_ok( $file, "Path::Class::Entity" );
305 25 isa_ok( $file, "Path::Class::File" );
306  
307 25 is( $file->basename, "foo.txt", "basename" );
308 }
309  
310 25 ▶ if ( HAVE_MX_TRAITS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&HAVE_MX_TRAITS()) 0 25 25
311 0 $self->no_live_objects;
312 0 my $s = $self->new_scope;
313  
314 0 my $obj = $self->lookup_ok("traits")->{obj};
315  
316 0 does_ok( $obj, "Some::Other::Role" );
317 0 does_ok( $obj, "Some::Third::Role" );
318  
319 0 is( $obj->other_role_attr, "foo", "trait attr" );
320
321 0 is( $obj->name, "blah", "normal attr" );
322 }
323  
324 25 ▶ if ( HAVE_MX_OP ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&HAVE_MX_OP()) 0 25 25
325 0 $self->no_live_objects;
326 0 my $s = $self->new_scope;
327  
328 0 my $one = $self->lookup_ok("op_one");
329  
330 0 does_ok( $one, "Some::Other::Role" );
331  
332 0 is( $one->other_role_attr, "after", "role attr" );
333  
334 0 my $two = $self->lookup_ok("op_two");
335  
336 0 does_ok( $two, "Some::Other::Role" );
337 0 does_ok( $two, "Some::Third::Role" );
338  
339 0 is( eval { $two->other_role_attr }, "after", "role attr" );
340 }
341 }
342  
343 2 __PACKAGE__
344  
345 __END__
« KiokuDB/TypeMap/Entry/StorableHook.pm ↑ Summary KiokuDB/Thunk.pm »