blib/lib/Attribute/Handlers.pm

filter: Statementstmt 94.0% 206 / 219 Branchbran 65.2% 77 / 118 Conditioncond 56.8% 29 / 51 MC/DCmcdc 30.0% 9 / 30 Subroutinesub 91.8% 34 / 37 Podpod 50.0% 1 / 2 totaltotal 77.9% 356 / 457 CC 104 SCAR 23.8
CC
104
Cov
80%
import
24.6
__ANON__
20.3
_apply_handler_AH_
14.3
CRAP 10.8
↑ Summary
1 package Attribute::Handlers;
2 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 our $AUTOLOAD;
7 5 our $VERSION = '1.03'; # remember to update version in POD!
8 # $DB::single=1;
9 5 ▶my $debug= $ENV{DEBUG_ATTRIBUTE_HANDLERS} || 0;
Condition50%1/2
$ENV{'DEBUG_ATTRIBUTE_HANDLERS'} || 0
l!l
05
MC/DC0%0/1
$ENV{'DEBUG_ATTRIBUTE_HANDLERS'} || 0
$ENV{'DEBUG_ATTRIBUTE_HANDLERS'}
Truth table50%1/2
A
A= $ENV{'DEBUG_ATTRIBUTE_HANDLERS'}
Aresult
11
00
10 5 my %symcache;
11 78 ▶sub findsym {
Subroutine findsym: called CC=10 SCAR=23.0
Pod documented
12 78 my ($pkg, $ref, $type) = @_;
13 78 ▶ return $symcache{$pkg,$ref} if $symcache{$pkg,$ref};
Branch: 1 branch
BranchTrueFalseTotal
if $symcache{join $;, $pkg, $ref} 1 77 78
14 77 ▶ $type ||= ref($ref);
Condition33%1/3
$type ||= ref $ref
l!l&&r!l&&!r
0770
MC/DC0%0/2
$type ||= ref $ref
$type ref $ref
Truth table33%1/3
A ||= B
A= $typeB= ref $ref
ABresult
1X1
011
000
15 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 77 my $symtab = \%{$pkg."::"};
17 77 for ( keys %$symtab ) { for my $sym ( $$symtab{$_} ) {
18 6073 ▶ if (ref $sym && $sym == $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sym and $sym == $ref) 6 6067 6073
Condition100%3/3
ref $sym and $sym == $ref
!ll&&!rl&&r
606256
MC/DC100%2/2
ref $sym and $sym == $ref
ref $sym $sym == $ref
Truth table100%3/3
A and B
A= ref $symB= $sym == $ref
ABresult
0X0
100
111
19 6 return $symcache{$pkg,$ref} = \*{"$pkg:\:$_"};
20 }
21 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6067 ▶ next unless ref ( \$sym ) eq 'GLOB';
Branch: 1 branch
BranchTrueFalseTotal
unless ref \$sym eq "GLOB" 5 6062 6067
23 return $symcache{$pkg,$ref} = \$sym
24 6062 ▶ if *{$sym}{$type} && *{$sym}{$type} == $ref;
Branch: 1 branch
BranchTrueFalseTotal
if *{$sym;}{$type} and *{$sym;}{$type} == $ref 35 6027 6062
Condition100%3/3
*{$sym;}{$type} and *{$sym;}{$type} == $ref
!ll&&!rl&&r
2993303435
MC/DC100%2/2
*{$sym;}{$type} and *{$sym;}{$type} == $ref
*{$sym;}{$type} *{$sym;}{$type} == $ref
Truth table100%3/3
A and B
A= *{$sym;}{$type}B= *{$sym;}{$type} == $ref
ABresult
0X0
100
111
25 }}
26 }
27  
28 5 my %validtype = (
29 VAR => [qw[SCALAR ARRAY HASH]],
30 ANY => [qw[SCALAR ARRAY HASH CODE]],
31 "" => [qw[SCALAR ARRAY HASH CODE]],
32 SCALAR => [qw[SCALAR]],
33 ARRAY => [qw[ARRAY]],
34 HASH => [qw[HASH]],
35 CODE => [qw[CODE]],
36 );
37 5 my %lastattr;
38 my @declarations;
39 5 my %raw;
40 5 my %phase;
41 5 my %sigil = (SCALAR=>'$', ARRAY=>'@', HASH=>'%');
42 5 my $global_phase = 0;
43 5 my %global_phases = (
44 BEGIN => 0,
45 CHECK => 1,
46 INIT => 2,
47 END => 3,
48 );
49 5 my @global_phases = qw(BEGIN CHECK INIT END);
50  
51 0 ▶sub _usage_AH_ {
Subroutine _usage_AH_: not called CC=1 SCAR=6.9
52 0 croak "Usage: use $_[0] autotie => {AttrName => TieClassName,...}";
53 }
54  
55 5 my $qual_id = qr/^[_a-z]\w*(::[_a-z]\w*)*$/i;
56  
57 6 ▶sub import {
Subroutine import: called CC=16 SCAR=32.0
58 6 my $class = shift @_;
59 6 ▶ return unless $class eq "Attribute::Handlers";
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq "Attribute::Handlers" 0 6 6
60 6 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 6 8
61 2 my $cmd = shift;
62 2 ▶ if ($cmd =~ /^autotie((?:ref)?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^autotie((?:ref)?)$/) { } 2 0 2
63 2 ▶ my $tiedata = ($1 ? '$ref, ' : '') . '@$data';
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 2 2
64 2 my $mapping = shift;
65 2 ▶ _usage_AH_ $class unless ref($mapping) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mapping eq "HASH" 0 2 2
66 2 ▶ while (my($attr, $tieclass) = each %$mapping) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$mapping) 4 2 6
67 4 $tieclass =~ s/^([_a-z]\w*(::[_a-z]\w*)*)(.*)/$1/is;
68 4 ▶ my $args = $3||'()';
Condition50%1/2
$3 || '()'
l!l
04
MC/DC0%0/1
$3 || '()'
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
69 2 ▶ _usage_AH_ $class unless $attr =~ $qual_id
Subroutine BEGIN: called CC=1 SCAR=0.7
Subroutine BEGIN: called CC=1 SCAR=0.7
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /$qual_id/i and $tieclass =~ /$qual_id/i and eval "use base q\000$tieclass\000; 1" 0 4 4
Condition33%2/6
$attr =~ /$qual_id/i and $tieclass =~ /$qual_id/i and eval "use base q\000$tieclass\000; 1"
!ll&&!rl&&r
004
$attr =~ /$qual_id/i and $tieclass =~ /$qual_id/i
!ll&&!rl&&r
004
MC/DC0%0/3
$attr =~ /$qual_id/i and $tieclass =~ /$qual_id/i and eval "use base q\000$tieclass\000; 1"
$attr =~ /$qual_id/i $tieclass =~ /$qual_id/i eval "use base q\000$tieclass\000; 1"
Truth table25%1/4
A and B and C
A= $attr =~ /$qual_id/iB= $tieclass =~ /$qual_id/iC= eval "use base q\000$tieclass\000; 1"
ABCresult
0XX0
10X0
1100
1111
70 && $tieclass =~ $qual_id
71 && eval "use base q\0$tieclass\0; 1";
72 4 ▶ if ($tieclass->isa('Exporter')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tieclass->isa("Exporter")) 0 4 4
73 0 local $Exporter::ExportLevel = 2;
74 0 $tieclass->import(eval $args);
75 }
76 4 my $code = qq{
77 : ATTR(VAR) {
78 my (\$ref, \$data) = \@_[2,4];
79 my \$was_arrayref = ref \$data eq 'ARRAY';
80 \$data = [ \$data ] unless \$was_arrayref;
81 my \$type = ref(\$ref)||"value (".(\$ref||"<undef>").")";
82 (\$type eq 'SCALAR')? tie \$\$ref,'$tieclass',$tiedata
83 :(\$type eq 'ARRAY') ? tie \@\$ref,'$tieclass',$tiedata
84 :(\$type eq 'HASH') ? tie \%\$ref,'$tieclass',$tiedata
85 : die "Can't autotie a \$type\n"
86 }
87 };
88  
89 4 ▶ if ($attr =~ /\A__CALLER__::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /\A__CALLER__::/) { } 1 3 4
90 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 1 my $add_import = caller;
92 0 ▶ my $next = defined &{ $add_import . '::import' } && \&{ $add_import . '::import' };
Condition50%1/2
defined &{$add_import . '::import';} && \&{$add_import . '::import';}
!ll
10
MC/DC0%0/1
defined &{$add_import . '::import';} && \&{$add_import . '::import';}
defined &{$add_import . '::import';}
Truth table50%1/2
A
A= defined &{$add_import . '::import';}
Aresult
00
11
93 1 ▶ *{ $add_import . '::import' } = sub {
Subroutine __ANON__: called CC=8 SCAR=24.7
94 2 my $caller = caller;
95 2 my $full_attr = $attr;
96 2 $full_attr =~ s/__CALLER__/$caller/;
97 2 ▶ eval qq{ sub $full_attr $code 1; }
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine BEGIN: called CC=1 SCAR=0.5
Subroutine Mine: called CC=7 SCAR=22.5
Subroutine Mine: called CC=7 SCAR=22.5
Branch: 9 branches
BranchTrueFalseTotal
eval " sub $full_attr $code 1; " or die "Internal error: $@" 2 0 2
unless $was_arrayref 2 0 2
$type eq 'SCALAR' ? : 2 0 2
$type eq 'ARRAY' ? : 0 0 0
$type eq 'HASH' ? : 0 0 0
unless $was_arrayref 1 1 2
$type eq 'SCALAR' ? : 1 1 2
$type eq 'ARRAY' ? : 1 0 1
$type eq 'HASH' ? : 0 0 0
Condition25%2/8
ref $ref || 'value (' . ($ref || '<undef>') . ')'
l!l
20
$ref || '<undef>'
l!l
00
ref $ref || 'value (' . ($ref || '<undef>') . ')'
l!l
20
$ref || '<undef>'
l!l
00
MC/DC0%0/1
ref $ref || 'value (' . ($ref || '<undef>') . ')'
ref $ref
MC/DC0%0/1
$ref || '<undef>'
$ref
MC/DC0%0/1
ref $ref || 'value (' . ($ref || '<undef>') . ')'
ref $ref
MC/DC0%0/1
$ref || '<undef>'
$ref
Truth table50%1/2
A
A= ref $ref
Aresult
11
00
Truth table0%0/2
A
A= $ref
Aresult
11
00
Truth table50%1/2
A
A= ref $ref
Aresult
11
00
Truth table0%0/2
A
A= $ref
Aresult
11
00
98 or die "Internal error: $@";
99  
100 2 ▶ goto &$next
Branch: 1 branch
BranchTrueFalseTotal
if $next 0 2 2
101 if $next;
102 2 ▶ my $uni = defined &UNIVERSAL::import && \&UNIVERSAL::import;
Condition50%1/2
defined &UNIVERSAL::import && \&UNIVERSAL::import
!ll
02
MC/DC0%0/1
defined &UNIVERSAL::import && \&UNIVERSAL::import
defined &UNIVERSAL::import
Truth table50%1/2
A
A= defined &UNIVERSAL::import
Aresult
00
11
103 2 for my $isa (@{ $add_import . '::ISA' }) {
104 0 ▶ if (my $import = $isa->can('import')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $import = $isa->can("import")) 0 0 0
105 0 ▶ goto &$import
Branch: 1 branch
BranchTrueFalseTotal
if $import != $uni 0 0 0
106 if $import != $uni;
107 }
108 }
109 2 ▶ goto &$uni
Branch: 1 branch
BranchTrueFalseTotal
if $uni 2 0 2
110 if $uni;
111 1 };
112 }
113 else {
114 3 ▶ $attr = caller()."::".$attr unless $attr =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /::/ 1 2 3
115 3 ▶ eval qq{ sub $attr $code 1; }
Subroutine BEGIN: called CC=1 SCAR=0.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
eval " sub $attr $code 1; " or die "Internal error: $@" 3 0 3
116 or die "Internal error: $@";
117 }
118 }
119 }
120 else {
121 0 croak "Can't understand $_";
122 }
123 }
124 }
125  
126 # On older perls, code attribute handlers run before the sub gets placed
127 # in its package. Since the :ATTR handlers need to know the name of the
128 # sub they're applied to, the name lookup (via findsym) needs to be
129 # delayed: we do it immediately before we might need to find attribute
130 # handlers from their name. However, on newer perls (which fix some
131 # problems relating to attribute application), a sub gets placed in its
132 # package before its attributes are processed. In this case, the
133 # delayed name lookup might be too late, because the sub we're looking
134 # for might have already been replaced. So we need to detect which way
135 # round this perl does things, and time the name lookup accordingly.
136 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
137 5 my $delayed;
138 sub Attribute::Handlers::_TEST_::MODIFY_CODE_ATTRIBUTES {
139 $delayed = \&Attribute::Handlers::_TEST_::t != $_[1];
140 return ();
141 }
142 5 ▶ sub Attribute::Handlers::_TEST_::t :T { }
Subroutine BEGIN: called CC=1 SCAR=0.0
143 5 ▶ *_delayed_name_resolution = sub() { $delayed };
Subroutine __ANON__: called CC=1 SCAR=0.0
144 5 undef &Attribute::Handlers::_TEST_::MODIFY_CODE_ATTRIBUTES;
145 5 undef &Attribute::Handlers::_TEST_::t;
146 }
147  
148 23 ▶sub _resolve_lastattr {
Subroutine _resolve_lastattr: called CC=6 SCAR=18.1
149 24 ▶ return unless $lastattr{ref};
Branch: 1 branch
BranchTrueFalseTotal
unless $lastattr{"ref"} 0 24 24
150 24 ▶ my $sym = findsym @lastattr{'pkg','ref'}
Branch: 1 branch
BranchTrueFalseTotal
my $sym = findsym(@lastattr{"pkg", "ref"}) or die qq[Internal error: $lastattr{"pkg"} symbol went missing] 23 1 24
151 or die "Internal error: $lastattr{pkg} symbol went missing";
152 24 my $name = *{$sym}{NAME};
153 23 ▶ warn "Declaration of $name attribute in package $lastattr{pkg} may clash with future reserved word\n"
Branch: 1 branch
BranchTrueFalseTotal
if $^W and not $name =~ /[A-Z]/ 0 24 24
Condition66%2/3
$^W and not $name =~ /[A-Z]/
!ll&&!rl&&r
2310
MC/DC0%0/2
$^W and not $name =~ /[A-Z]/
$^W not $name =~ /[A-Z]/
Truth table66%2/3
A and not(B)
A= $^WB= not $name =~ /[A-Z]/
ABresult
0X0
100
111
154 if $^W and $name !~ /[A-Z]/;
155 23 foreach ( @{$validtype{$lastattr{type}}} ) {
156 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
157 53 *{"$lastattr{pkg}::_ATTR_${_}_${name}"} = $lastattr{ref};
158 }
159 23 %lastattr = ();
160 }
161  
162 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=3 SCAR=22.0
163 0 ▶ return if $AUTOLOAD =~ /::DESTROY$/;
Branch: 1 branch
BranchTrueFalseTotal
if $Attribute::Handlers::AUTOLOAD =~ /::DESTROY$/ 1 0 1
164 0 my ($class) = $AUTOLOAD =~ m/(.*)::/g;
165 0 ▶ $AUTOLOAD =~ m/_ATTR_(.*?)_(.*)/ or
Branch: 1 branch
BranchTrueFalseTotal
$Attribute::Handlers::AUTOLOAD =~ /_ATTR_(.*?)_(.*)/ or croak("Can't locate class method '$Attribute::Handlers::AUTOLOAD' via package '${class}'") 0 0 0
166 croak "Can't locate class method '$AUTOLOAD' via package '$class'";
167 0 croak "Attribute handler '$2' doesn't handle $1 attributes";
168 }
169  
170 5 ▶my $builtin = $] ge '5.027000'
Branch: 1 branch
BranchTrueFalseTotal
$] ge '5.027000' ? : 5 0 5
171 ? qr/lvalue|method|shared/
172 : qr/lvalue|method|locked|shared|unique/;
173  
174 20 ▶sub _gen_handler_AH_() {
Subroutine _gen_handler_AH_: called CC=1 SCAR=0.0
175 80 ▶ return sub {
Subroutine __ANON__: called CC=20 SCAR=30.1
176 80 ▶ _resolve_lastattr if _delayed_name_resolution;
Branch: 1 branch
BranchTrueFalseTotal
if &_delayed_name_resolution() 0 80 80
177 80 my ($pkg, $ref, @attrs) = @_;
178 80 my (undef, $filename, $linenum) = caller 2;
179 80 foreach (@attrs) {
180 81 ▶ my ($attr, $data) = /^([a-z_]\w*)(?:[(](.*)[)])?$/is or next;
Branch: 1 branch
BranchTrueFalseTotal
() = /^([a-z_]\w*)(?:[(](.*)[)])?$/is or next 81 0 81
181 81 ▶ if ($attr eq 'ATTR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr eq 'ATTR') { } 23 58 81
182 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
183 23 ▶ $data ||= "ANY";
Condition100%2/2
$data ||= "ANY"
l!l
212
MC/DC100%1/1
$data ||= "ANY"
$data
Truth table100%2/2
A
A= $data
Aresult
11
00
184 23 $raw{$ref} = $data =~ s/\s*,?\s*RAWDATA\s*,?\s*//;
185 23 ▶ $phase{$ref}{BEGIN} = 1
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ s/\s*,?\s*(BEGIN)\s*,?\s*// 2 21 23
186 if $data =~ s/\s*,?\s*(BEGIN)\s*,?\s*//;
187 23 ▶ $phase{$ref}{INIT} = 1
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ s/\s*,?\s*(INIT)\s*,?\s*// 1 22 23
188 if $data =~ s/\s*,?\s*(INIT)\s*,?\s*//;
189 23 ▶ $phase{$ref}{END} = 1
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ s/\s*,?\s*(END)\s*,?\s*// 1 22 23
190 if $data =~ s/\s*,?\s*(END)\s*,?\s*//;
191 $phase{$ref}{CHECK} = 1
192 if $data =~ s/\s*,?\s*(CHECK)\s*,?\s*//
193 23 ▶ || ! keys %{$phase{$ref}};
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ s/\s*,?\s*(CHECK)\s*,?\s*// or not keys %{$phase{$ref};} 18 5 23
Condition100%3/3
$data =~ s/\s*,?\s*(CHECK)\s*,?\s*// or not keys %{$phase{$ref};}
l!l&&r!l&&!r
1175
MC/DC100%2/2
$data =~ s/\s*,?\s*(CHECK)\s*,?\s*// or not keys %{$phase{$ref};}
$data =~ s/\s*,?\s*(CHECK)\s*,?\s*// not keys %{$phase{$ref};}
Truth table100%3/3
A or not(B)
A= $data =~ s/\s*,?\s*(CHECK)\s*,?\s*//B= not keys %{$phase{$ref};}
ABresult
1X1
011
000
194 # Added for cleanup to not pollute next call.
195 23 ▶ (%lastattr = ()),
Branch: 1 branch
BranchTrueFalseTotal
if keys %lastattr 0 23 23
196 croak "Can't have two ATTR specifiers on one subroutine"
197 if keys %lastattr;
198 croak "Bad attribute type: ATTR($data)"
199 23 ▶ unless $validtype{$data};
Branch: 1 branch
BranchTrueFalseTotal
unless $validtype{$data} 0 23 23
200 23 %lastattr=(pkg=>$pkg,ref=>$ref,type=>$data);
201 23 ▶ _resolve_lastattr unless _delayed_name_resolution;
Branch: 1 branch
BranchTrueFalseTotal
unless &_delayed_name_resolution() 23 0 23
202 }
203 else {
204 58 my $type = ref $ref;
205 58 my $handler = $pkg->can("_ATTR_${type}_${attr}");
206 58 ▶ next unless $handler;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 2 56 58
207 my $decl = [$pkg, $ref, $attr, $data,
208 56 $raw{$handler}, $phase{$handler}, $filename, $linenum];
209 56 foreach my $gphase (@global_phases) {
210 _apply_handler_AH_($decl,$gphase)
211 224 ▶ if $global_phases{$gphase} <= $global_phase;
Branch: 1 branch
BranchTrueFalseTotal
if $global_phases{$gphase} <= $global_phase 130 94 224
212 }
213 56 ▶ if ($global_phase != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global_phase != 0) { } 37 19 56
214 # if _gen_handler_AH_ is being called after
215 # CHECK it's for a lexical, so make sure
216 # it didn't want to run anything later
217
218 37 local $Carp::CarpLevel = 2;
219 carp "Won't be able to apply END handler"
220 37 ▶ if $phase{$handler}{END};
Branch: 1 branch
BranchTrueFalseTotal
if $phase{$handler}{"END"} 1 36 37
221 }
222 else {
223 19 push @declarations, $decl
224 }
225 }
226 78 $_ = undef;
227 }
228 79 ▶ return grep {defined && !/$builtin/} @attrs;
Condition66%2/3
defined $_ && !/$builtin/
!ll&&!rl&&r
7802
MC/DC50%1/2
defined $_ && !/$builtin/
defined $_ !/$builtin/
Truth table66%2/3
A && not(B)
A= defined $_B= !/$builtin/
ABresult
0X0
100
111
229 }
230 20 }
231  
232 {
233 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
234 20 *{"Attribute::Handlers::UNIVERSAL::MODIFY_${_}_ATTRIBUTES"} =
235 5 _gen_handler_AH_ foreach @{$validtype{ANY}};
236 }
237 5 ▶push @UNIVERSAL::ISA, 'Attribute::Handlers::UNIVERSAL'
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^Attribute::Handlers::UNIVERSAL$/, @UNIVERSAL::ISA 5 0 5
238 unless grep /^Attribute::Handlers::UNIVERSAL$/, @UNIVERSAL::ISA;
239  
240 187 ▶sub _apply_handler_AH_ {
Subroutine _apply_handler_AH_: called CC=13 SCAR=26.6
241 187 my ($declaration, $phase) = @_;
242 187 my ($pkg, $ref, $attr, $data, $raw, $handlerphase, $filename, $linenum) = @$declaration;
243 187 ▶ return unless $handlerphase->{$phase};
Branch: 1 branch
BranchTrueFalseTotal
unless $handlerphase->{$phase} 132 55 187
244 55 ▶ print STDERR "Handling $attr on $ref in $phase with [$data]\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 55 55
245 if $debug;
246 55 my $type = ref $ref;
247 55 my $handler = "_ATTR_${type}_${attr}";
248 55 my $sym = findsym($pkg, $ref);
249 55 ▶ $sym ||= $type eq 'CODE' ? 'ANON' : 'LEXICAL';
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'CODE' ? : 0 36 36
Condition66%2/3
$sym ||= $type eq "CODE" ? "ANON" : "LEXICAL"
l!l&&r!l&&!r
19360
MC/DC0%0/2
$sym ||= $type eq "CODE" ? "ANON" : "LEXICAL"
$sym $type eq "CODE" ? "ANON" : "LEXICAL"
Truth table66%2/3
A ||= B
A= $symB= $type eq "CODE" ? "ANON" : "LEXICAL"
ABresult
1X1
011
000
250 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
251 55 ▶ if (!$raw && defined($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $raw and defined $data) 45 10 55
Condition66%2/3
not $raw and defined $data
!ll&&!rl&&r
01045
MC/DC50%1/2
not $raw and defined $data
not $raw defined $data
Truth table66%2/3
not(A) and B
A= not $rawB= defined $data
ABresult
0X0
100
111
252 45 ▶ if ($data ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data ne '') { } 45 0 45
253 # keeping the minimum amount of code inside the eval string
254 # makes debugging perl internals issues with this logic easier.
255 45 my $code= "package $pkg; my \$ref= [$data]; \$data= \$ref; 1";
256 45 ▶ print STDERR "Evaling: '$code'\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 45 45
257 if $debug;
258 0 ▶ local $SIG{__WARN__} = sub{ die };
Subroutine __ANON__: not called CC=1 SCAR=1.2
259 5 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
260 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
261 # Note in production we do not need to use the return value from
262 # the eval or even consult $@ after the eval - if the evaled code
263 # compiles and runs successfully then it will update $data with
264 # the compiled form, if it fails then $data stays unchanged. The
265 # return value and $@ are only used for debugging purposes.
266 # IOW we could just replace the following with eval($code);
267 45 ▶ eval($code) or do {
Branch: 1 branch
BranchTrueFalseTotal
eval $code or do { print STDERR "Eval failed: $@" if $debug } 43 2 45
268 2 ▶ print STDERR "Eval failed: $@"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
269 if $debug;
270 };
271 }
272 0 else { $data = undef }
273 }
274  
275 # now call the handler with the $data decoded (maybe)
276 $pkg->$handler($sym,
277 55 ▶ (ref $sym eq 'GLOB' ? *{$sym}{ref $ref}||$ref : $ref),
Branch: 1 branch
BranchTrueFalseTotal
ref $sym eq 'GLOB' ? : 19 36 55
Condition33%1/3
*{$sym;}{ref $ref} or $ref
l!l&&r!l&&!r
1900
MC/DC0%0/2
*{$sym;}{ref $ref} or $ref
*{$sym;}{ref $ref} $ref
Truth table33%1/3
A or B
A= *{$sym;}{ref $ref}B= $ref
ABresult
1X1
011
000
278 $attr,
279 $data,
280 $phase,
281 $filename,
282 $linenum,
283 );
284 55 return 1;
285 }
286  
287 {
288 5 ▶ no warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
289 6 ▶ CHECK {
Subroutine CHECK: called CC=3 SCAR=11.1
290 6 $global_phase++;
291 6 ▶ _resolve_lastattr if _delayed_name_resolution;
Branch: 1 branch
BranchTrueFalseTotal
if &_delayed_name_resolution() 0 5 5
292 6 foreach my $decl (@declarations) {
293 20 _apply_handler_AH_($decl, 'CHECK');
294 }
295 }
296  
297 5 ▶ INIT {
Subroutine INIT: called CC=2 SCAR=6.9
298 6 $global_phase++;
299 6 foreach my $decl (@declarations) {
300 19 _apply_handler_AH_($decl, 'INIT');
301 }
302 }
303 }
304  
305 5 ▶END {
Subroutine END: called CC=2 SCAR=6.9
306 5 $global_phase++;
307 5 foreach my $decl (@declarations) {
308 19 _apply_handler_AH_($decl, 'END');
309 }
310 }
311  
312 5 1;
313 __END__
↑ Summary