blib/lib/MooseX/hasn/t.pm

filter: Statementstmt 89.2% 50 / 56 Branchbran 68.1% 15 / 22 Conditioncond 37.5% 9 / 24 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 65.8% 85 / 129 CC 23 SCAR 27.7
CC
23
Cov
73%
t
27.7
__ANON__
8.1
__ANON__
2.3
CRAP 16.0
↑ Summary
1 package MooseX::hasn::t;
2  
3 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 $MooseX::hasn::t::AUTHORITY = 'cpan:TOBYINK';
5 2 $MooseX::hasn::t::VERSION = '0.003';
6 }
7  
8 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict qw(subs vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our @CARP_NOT = qw(Moose::Meta::Method::Overridden);
13  
14 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub hasn::t
18 3 ▶{
Subroutine t: called CC=17 SCAR=33.2
19 3 ▶ my $opts = ref($_[0]) eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 1 2 3
20 3 my ($symbol, %args) = @_;
21 3 ▶ my $caller = $opts->{caller} || caller;
Condition66%2/3
$opts->{'caller'} || caller
l!l&&r!l&&!r
120
MC/DC0%0/2
$opts->{'caller'} || caller
$opts->{'caller'} caller
Truth table66%2/3
A || B
A= $opts->{'caller'}B= caller
ABresult
1X1
011
000
22
23 3 ▶ if (ref $symbol eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $symbol eq "ARRAY") 1 2 3
24 {
25 1 hasn::t({caller=>$caller}, $_, %args) for @$symbol;
26 1 return;
27 }
28
29 2 my $ERROR = q(Can't locate object method "%s" via package "%s");
30
31 2 my @subs;
32 2 ▶ if (my $attr = $caller->meta->find_attribute_by_name($symbol))
Branch: 1 branch
BranchTrueFalseTotal
if (my $attr = $caller->meta->find_attribute_by_name($symbol)) { } 1 1 2
33 {
34 1 foreach my $role (qw(accessor reader writer predicate clearer initializer))
35 {
36 6 my $sub = $attr->$role;
37 6 ▶ push @subs, $sub if defined $sub && !ref $sub;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sub and not ref $sub 2 4 6
Condition66%2/3
defined $sub and not ref $sub
!ll&&!rl&&r
402
MC/DC50%1/2
defined $sub and not ref $sub
defined $sub not ref $sub
Truth table66%2/3
A and not(B)
A= defined $subB= not ref $sub
ABresult
0X0
100
111
38 }
39
40 1 ▶ if ($attr->is_required and $attr->has_default)
Branch: 3 branches
BranchTrueFalseTotal
if ($attr->is_required and $attr->has_default) { } 0 1 1
elsif ($attr->is_required and exists $args{'default'}) { } 1 0 1
elsif ($attr->is_required) { } 0 0 0
Condition33%1/3
$attr->is_required and $attr->has_default
!ll&&!rl&&r
010
MC/DC0%0/2
$attr->is_required and $attr->has_default
$attr->is_required $attr->has_default
Truth table33%1/3
A and B
A= $attr->is_requiredB= $attr->has_default
ABresult
0X0
100
111
41 {
42 # OK
43 }
44 ▶ elsif ($attr->is_required and exists $args{default})
Condition33%1/3
$attr->is_required and exists $args{"default"}
!ll&&!rl&&r
001
MC/DC0%0/2
$attr->is_required and exists $args{"default"}
$attr->is_required exists $args{"default"}
Truth table33%1/3
A and B
A= $attr->is_requiredB= exists $args{"default"}
ABresult
0X0
100
111
45 {
46 1 ▶ my $init_arg = $attr->init_arg || $symbol;
Condition33%1/3
$attr->init_arg || $symbol
l!l&&r!l&&!r
100
MC/DC0%0/2
$attr->init_arg || $symbol
$attr->init_arg $symbol
Truth table33%1/3
A || B
A= $attr->init_argB= $symbol
ABresult
1X1
011
000
47
48 1 ▶ unless ($caller->can('BUILDARGS'))
Branch: 1 branch
BranchTrueFalseTotal
unless ($caller->can("BUILDARGS")) 0 1 1
49 {
50 0 ▶ *{"$caller\::BUILDARGS"} = sub { shift; @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 }
52
53 $caller->meta->add_around_method_modifier(BUILDARGS => sub
54 1 ▶ {
Subroutine __ANON__: called CC=5 SCAR=20.9
55 1 my ($orig, $class, @args) = @_;
56 1 ▶ my $d = ref $args{default} eq 'CODE' ? $args{default}->() : $args{default};
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'default'} eq 'CODE' ? : 1 0 1
57 1 ▶ if (@args==1 and ref $args[0] eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1 and ref $args[0] eq 'HASH') { } 0 1 1
Condition33%1/3
@args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1 ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
58 {
59 0 ▶ $args[0]{$init_arg} //= $d;
Condition0%0/3
$args[0]{$init_arg} //= $d
l!l&&r!l&&!r
000
MC/DC0%0/2
$args[0]{$init_arg} //= $d
$args[0]{$init_arg} $d
Truth table0%0/3
A //= B
A= $args[0]{$init_arg}B= $d
ABresult
1X1
011
000
60 }
61 else
62 {
63 1 push @args, $init_arg, $d;
64 }
65
66 1 $class->$orig(@args);
67 1 });
68 }
69 elsif ($attr->is_required)
70 {
71 0 croak "can't \"hasn't $symbol\", because $symbol is required and has no default";
72 }
73 }
74 else
75 {
76 1 @subs = $symbol;
77 }
78
79 2 foreach my $sub (@subs)
80 {
81 $caller->meta->add_override_method_modifier($sub => sub
82 2 ▶ {
Subroutine __ANON__: called CC=2 SCAR=8.1
83 2 my ($invocant, @args) = @_;
84 2 ▶ croak sprintf($ERROR, $sub, (blessed $invocant or $caller));
Condition33%1/3
builtin::blessed($invocant) || $caller
l!l&&r!l&&!r
200
MC/DC0%0/2
builtin::blessed($invocant) || $caller
builtin::blessed($invocant) $caller
Truth table33%1/3
A || B
A= builtin::blessed($invocant)B= $caller
ABresult
1X1
011
000
85 3 });
86 }
87
88 2 my $can = $caller->can('can');
89 2 ▶ *{"$caller\::can"} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
90 10 my ($invocant, $m) = @_;
91 10 ▶ return if $m ~~ [@subs];
Branch: 1 branch
BranchTrueFalseTotal
if $m ~~ [@subs] 2 8 10
92 8 goto $can;
93 }
94 2 }
95  
96 2 __PACKAGE__
97 __END__
↑ Summary