Lexical/Accessor.pm

filter: Statementstmt 89.0% 49 / 55 Branchbran 64.7% 22 / 34 Conditioncond 57.1% 8 / 14 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 92.3% 12 / 13 Podpod 16.6% 1 / 6 totaltotal 71.7% 94 / 131 CC 23 SCAR 22.0
CC
23
Cov
77%
canonicalize_is
16.1
canonicalize_opts
10.1
inline_to_coderef
3.3
CRAP 9.0
« Sub/Accessor/Small.pm ↑ Summary Sub/HandlesVia/Toolkit/SubAccessorSmall.pm »
1 7 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶no warnings qw( void once uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Lexical::Accessor;
7  
8 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Sub::Accessor::Small ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 our $AUTHORITY = 'cpan:TOBYINK';
12 7 our $VERSION = '1.001002';
13 7 our @EXPORT = qw/ lexical_has /;
14 7 our @ISA = qw/ Sub::Accessor::Small /;
15  
16 7 ▶sub _generate_lexical_has : method
Subroutine _generate_lexical_has: called CC=1 SCAR=0.0
17 {
18 7 my $me = shift;
19 7 my $code = $me->_generate_has(@_);
20 7 return Sub::Accessor::Small::set_subname( "$me\::lexical_has", $code );
21 }
22  
23 0 ▶sub lexical_has : method
Subroutine lexical_has: not called CC=1 SCAR=6.9
Pod documented
24 {
25 0 my $has = $_[0]->can('has');
26 0 goto $has;
27 }
28
29 42 ▶sub inline_to_coderef : method
Subroutine inline_to_coderef: called CC=3 SCAR=12.0
Pod undocumented
30 {
31 42 my $me = shift;
32 42 my ($method_type, $code) = @_;
33 42 my $coderef = $me->SUPER::inline_to_coderef(@_);
34 ( $me->{package} and defined $me->{slot} )
35 42 ▶ ? Sub::Accessor::Small::set_subname( "$me->{package}\::__LEXICAL__[$me->{slot}]", $coderef )
Branch: 1 branch
BranchTrueFalseTotal
$me->{'package'} && defined $me->{'slot'} ? : 42 0 42
Condition33%1/3
$me->{"package"} and defined $me->{"slot"}
!ll&&!rl&&r
0042
MC/DC0%0/2
$me->{"package"} and defined $me->{"slot"}
$me->{"package"} defined $me->{"slot"}
Truth table33%1/3
A and B
A= $me->{"package"}B= defined $me->{"slot"}
ABresult
0X0
100
111
36 : $coderef
37 }
38  
39 42 ▶sub accessor_kind : method
Subroutine accessor_kind: called CC=1 SCAR=0.0
Pod undocumented
40 {
41 42 return 'lexical';
42 }
43  
44 26 ▶sub canonicalize_is : method
Subroutine canonicalize_is: called CC=13 SCAR=27.8
Pod undocumented
45 {
46 26 my $me = shift;
47
48 26 ▶ if ($me->{is} eq 'rw')
Branch: 4 branches
BranchTrueFalseTotal
if ($me->{'is'} eq 'rw') { } 5 21 26
elsif ($me->{'is'} eq 'ro') { } 4 17 21
elsif ($me->{'is'} eq 'rwp') { } 4 13 17
elsif ($me->{'is'} eq 'lazy') { } 4 9 13
49 {
50 $me->{accessor} = \(my $tmp)
51 5 ▶ if !exists($me->{accessor});
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"accessor"} 0 5 5
52 }
53 elsif ($me->{is} eq 'ro')
54 {
55 $me->{reader} = \(my $tmp)
56 4 ▶ if !exists($me->{reader});
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"reader"} 0 4 4
57 }
58 elsif ($me->{is} eq 'rwp')
59 {
60 $me->{reader} = \(my $tmp1)
61 4 ▶ if !exists($me->{reader});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"reader"} 0 4 4
62 $me->{writer} = \(my $tmp2)
63 4 ▶ if !exists($me->{writer});
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"writer"} 0 4 4
64 }
65 elsif ($me->{is} eq 'lazy')
66 {
67 $me->{reader} = \(my $tmp)
68 4 ▶ if !exists($me->{reader});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"reader"} 0 4 4
69 $me->{lazy} = 1
70 4 ▶ if !exists($me->{lazy});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"lazy"} 4 0 4
71 $me->{builder} = 1
72 4 ▶ unless $me->{builder} || $me->{default};
Branch: 1 branch
BranchTrueFalseTotal
unless $me->{"builder"} or $me->{"default"} 0 4 4
Condition33%1/3
$me->{"builder"} or $me->{"default"}
l!l&&r!l&&!r
040
MC/DC0%0/2
$me->{"builder"} or $me->{"default"}
$me->{"builder"} $me->{"default"}
Truth table33%1/3
A or B
A= $me->{"builder"}B= $me->{"default"}
ABresult
1X1
011
000
73 }
74 }
75  
76 26 ▶sub canonicalize_opts : method
Subroutine canonicalize_opts: called CC=8 SCAR=23.1
Pod undocumented
77 {
78 26 my $me = shift;
79 26 $me->SUPER::canonicalize_opts(@_);
80  
81 26 ▶ if (defined $me->{init_arg})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{"init_arg"}) 0 26 26
82 {
83 0 croak("Invalid init_arg=>defined; private attributes cannot be initialized in the constructor");
84 }
85
86 26 ▶ if ($me->{required})
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"required"}) 0 26 26
87 {
88 0 croak("Invalid required=>1; private attributes cannot be initialized in the constructor");
89 }
90
91 26 ▶ if (defined $me->{lazy} and not $me->{lazy})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{'lazy'} and not $me->{'lazy'}) { } 0 26 26
Condition66%2/3
defined $me->{"lazy"} and not $me->{"lazy"}
!ll&&!rl&&r
2240
MC/DC0%0/2
defined $me->{"lazy"} and not $me->{"lazy"}
defined $me->{"lazy"} not $me->{"lazy"}
Truth table66%2/3
A and not(B)
A= defined $me->{"lazy"}B= not $me->{"lazy"}
ABresult
0X0
100
111
92 {
93 0 croak("Invalid lazy=>0; private attributes cannot be eager");
94 }
95 else
96 {
97 26 ▶ $me->{lazy} ||= 1 if $me->{default} || $me->{builder};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"default"} or $me->{"builder"} 5 21 26
Condition80%4/5
$me->{"default"} or $me->{"builder"}
l!l&&r!l&&!r
5021
$me->{"lazy"} ||= 1
l!l
41
MC/DC50%1/2
$me->{"default"} or $me->{"builder"}
$me->{"default"} $me->{"builder"}
MC/DC100%1/1
$me->{"lazy"} ||= 1
$me->{"lazy"}
Truth table66%2/3
A or B
A= $me->{"default"}B= $me->{"builder"}
ABresult
1X1
011
000
Truth table100%2/2
A
A= $me->{"lazy"}
Aresult
11
00
98 }
99
100 # for my $type (qw/ reader writer accessor clearer predicate /)
101 # {
102 # if (defined($me->{$type}) and not ref($me->{$type}) eq q(SCALAR))
103 # {
104 # croak("Expected $type to be a scalar ref; not '$me->{$type}'");
105 # }
106 # }
107 }
108  
109 sub expand_handles
110 1 ▶{
Subroutine expand_handles: called CC=2 SCAR=7.4
Pod undocumented
111 1 my $me = shift;
112
113 1 ▶ if (ref($me->{handles}) eq q(ARRAY))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $me->{"handles"} eq "ARRAY") 1 0 1
114 {
115 1 return @{$me->{handles}};
116 }
117
118 0 croak "Expected delegations to be a reference to an array; got $me->{handles}";
119 }
120  
121 7 1;
122  
123 __END__
« Sub/Accessor/Small.pm ↑ Summary Sub/HandlesVia/Toolkit/SubAccessorSmall.pm »