| 1 | package Attribute::Handlers::Clean; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use attributes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Perlmazing (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | our $VERSION = '1.06'; # remember to update version in POD! | |||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | my %symcache; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 74 | ▶ | sub findsym { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findsym: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 74 | my ($pkg, $ref, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 74 | ▶ | return $symcache{$pkg,$ref} if $symcache{$pkg,$ref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 73 | ▶ | $type ||= ref($ref); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type ||= ref $ref
MC/DC0%0/2
$type ||= ref $ref
$type
ref $ref
Truth table33%1/3
A ||= B
A= $typeB= ref $ref
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 73 | my $symtab = \%{$pkg."::"}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 73 | for (keys %$symtab) { | |||||||||||||||||||||||||||||||||||||||||
| 20 | 7438 | for my $sym ($$symtab{$_}) { | |||||||||||||||||||||||||||||||||||||||||
| 21 | 7438 | ▶ | if (ref $sym && $sym == $ref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $sym and $sym == $ref
MC/DC0%0/2
ref $sym and $sym == $ref
ref $sym
$sym == $ref
Truth table66%2/3
A and B
A= ref $symB= $sym == $ref
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | return $symcache{$pkg,$ref} = \*{"$pkg:\:$_"}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 7438 | ▶ | next unless ref (\$sym) eq 'GLOB'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | return $symcache{$pkg,$ref} = \$sym | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 7434 | ▶ | if *{$sym}{$type} && *{$sym}{$type} == $ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
*{$sym;}{$type} and *{$sym;}{$type} == $ref
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
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | my %validtype = ( | |||||||||||||||||||||||||||||||||||||||||
| 33 | VAR => [qw[SCALAR ARRAY HASH]], | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ANY => [qw[SCALAR ARRAY HASH CODE]], | ||||||||||||||||||||||||||||||||||||||||||
| 35 | "" => [qw[SCALAR ARRAY HASH CODE]], | ||||||||||||||||||||||||||||||||||||||||||
| 36 | SCALAR => [qw[SCALAR]], | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ARRAY => [qw[ARRAY]], | ||||||||||||||||||||||||||||||||||||||||||
| 38 | HASH => [qw[HASH]], | ||||||||||||||||||||||||||||||||||||||||||
| 39 | CODE => [qw[CODE]], | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | my %lastattr; | |||||||||||||||||||||||||||||||||||||||||
| 42 | my @declarations; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | my %raw; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | my %phase; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | my %sigil = (SCALAR=>'$', ARRAY=>'@', HASH=>'%'); | |||||||||||||||||||||||||||||||||||||||||
| 46 | 4 | my $global_phase = 0; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | my %global_phases = ( | |||||||||||||||||||||||||||||||||||||||||
| 48 | BEGIN => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | CHECK => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | INIT => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | END => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | my @global_phases = qw(BEGIN CHECK INIT END); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub _usage_AH_ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage_AH_: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | croak "Usage: use $_[0] autotie => {AttrName => TieClassName,...}"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my $qual_id = qr/^[_a-z]\w*(::[_a-z]\w*)*$/i; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 7 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=20 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | my $class = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | my @caller_0 = caller 0; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 7 | my @caller_1 = caller 1; | |||||||||||||||||||||||||||||||||||||||||
| 66 | # Allow just calling "package->import" inside of subclses own import method, to mean their caller should get the same import effect from this module - in the same style of warnings->unimport | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | ▶ | my $caller = (@caller_1 and $caller_1[3] eq "$caller_0[0]::import") ? $caller_1[0] : $caller_0[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@caller_1 and $caller_1[3] eq "$caller_0[0]::import"
MC/DC0%0/2
@caller_1 and $caller_1[3] eq "$caller_0[0]::import"
@caller_1
$caller_1[3] eq "$caller_0[0]::import"
Truth table33%1/3
A and B
A= @caller_1B= $caller_1[3] eq "$caller_0[0]::import"
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | warnings->unimport('reserved'); | |||||||||||||||||||||||||||||||||||||||||
| 70 | 7 | ▶ | push (@{"${caller}::ISA"}, $class) unless $caller eq $class or grep {$_ eq $class} @{"${caller}::ISA"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$caller eq $class or grep {$_ eq $class;} @{"${caller}::ISA";}
MC/DC50%1/2
$caller eq $class or grep {$_ eq $class;} @{"${caller}::ISA";}
$caller eq $class
grep {$_ eq $class;} @{"${caller}::ISA";}
Truth table66%2/3
A or B
A= $caller eq $classB= grep {$_ eq $class;} @{"${caller}::ISA";}
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 7 | for (@{$validtype{ANY}}) { | |||||||||||||||||||||||||||||||||||||||||
| 72 | 28 | ▶ | *{"${caller}::MODIFY_${_}_ATTRIBUTES"} = _gen_handler_AH_() unless defined *{"${caller}::MODIFY_${_}_ATTRIBUTES"}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | ▶ | return unless $class eq __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | if ($cmd =~ /^autotie((?:ref)?)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | my $tiedata = ($1 ? '$ref, ' : '') . '@$data'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | my $mapping = shift; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | _usage_AH_ $class unless ref($mapping) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | while (my($attr, $tieclass) = each %$mapping) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | $tieclass =~ s/^([_a-z]\w*(::[_a-z]\w*)*)(.*)/$1/is; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | my $args = $3||'()'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$3 || '()'
MC/DC0%0/1
$3 || '()'
$3
Truth table50%1/2
A
A= $3
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | _usage_AH_ $class unless $attr =~ $qual_id && $tieclass =~ $qual_id && eval "use base q\0$tieclass\0; 1"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Branch: 1 branch
Condition33%2/6
$attr =~ /$qual_id/ and $tieclass =~ /$qual_id/ and eval "use base q\000$tieclass\000; 1"
$attr =~ /$qual_id/ and $tieclass =~ /$qual_id/
MC/DC0%0/3
$attr =~ /$qual_id/ and $tieclass =~ /$qual_id/ and eval "use base q\000$tieclass\000; 1"
$attr =~ /$qual_id/
$tieclass =~ /$qual_id/
eval "use base q\000$tieclass\000; 1"
Truth table25%1/4
A and B and C
A= $attr =~ /$qual_id/B= $tieclass =~ /$qual_id/C= eval "use base q\000$tieclass\000; 1"
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | if ($tieclass->isa('Exporter')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | local $Exporter::ExportLevel = 2; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $tieclass->import(eval $args); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $attr =~ s/__CALLER__/caller(1)/e; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | $attr = caller()."::".$attr unless $attr =~ /::/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | eval '# line '.__LINE__.' "'.__FILE__.qq{" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | sub $attr : ATTR(VAR) { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | my (\$ref, \$data) = \@_[2,4]; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | my \$was_arrayref = ref \$data eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | \$data = [ \$data ] unless \$was_arrayref; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | my \$type = ref(\$ref)||"value (".(\$ref||"<undef>").")"; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | (\$type eq 'SCALAR') ? | ||||||||||||||||||||||||||||||||||||||||||
| 99 | tie \$\$ref,'$tieclass',$tiedata : | ||||||||||||||||||||||||||||||||||||||||||
| 100 | (\$type eq 'ARRAY') ? | ||||||||||||||||||||||||||||||||||||||||||
| 101 | tie \@\$ref,'$tieclass',$tiedata : | ||||||||||||||||||||||||||||||||||||||||||
| 102 | (\$type eq 'HASH') ? | ||||||||||||||||||||||||||||||||||||||||||
| 103 | tie \%\$ref,'$tieclass',$tiedata : | ||||||||||||||||||||||||||||||||||||||||||
| 104 | die "Can't autotie a \$type\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | } 1 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } or die "Internal error: $@"; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | croak "Can't understand $_"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # On older perls, code attribute handlers run before the sub gets placed | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # in its package. Since the :ATTR handlers need to know the name of the | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # sub they're applied to, the name lookup (via findsym) needs to be | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # delayed: we do it immediately before we might need to find attribute | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # handlers from their name. However, on newer perls (which fix some | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # problems relating to attribute application), a sub gets placed in its | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # package before its attributes are processed. In this case, the | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # delayed name lookup might be too late, because the sub we're looking | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # for might have already been replaced. So we need to detect which way | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # round this perl does things, and time the name lookup accordingly. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | my $delayed; | |||||||||||||||||||||||||||||||||||||||||
| 126 | sub Attribute::Handlers::Clean::_TEST_::MODIFY_CODE_ATTRIBUTES { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | $delayed = \&Attribute::Handlers::Clean::_TEST_::t != $_[1]; | ||||||||||||||||||||||||||||||||||||||||||
| 128 | return (); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | sub Attribute::Handlers::Clean::_TEST_::t :T { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | ▶ | *_delayed_name_resolution = sub() { $delayed }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | undef &Attribute::Handlers::Clean::_TEST_::MODIFY_CODE_ATTRIBUTES; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | undef &Attribute::Handlers::Clean::_TEST_::t; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 22 | ▶ | sub _resolve_lastattr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_lastattr: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 22 | ▶ | return unless $lastattr{ref}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 22 | ▶ | my $sym = findsym @lastattr{'pkg','ref'} or die "Internal error: $lastattr{pkg} symbol went missing"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 22 | my $name = *{$sym}{NAME}; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 22 | ▶ | warn "Declaration of $name attribute in package $lastattr{pkg} may clash with future reserved word\n" if $^W and $name !~ /[A-Z]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$^W and not $name =~ /[A-Z]/
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]/
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 22 | foreach ( @{$validtype{$lastattr{type}}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 48 | *{"$lastattr{pkg}::_ATTR_${_}_${name}"} = $lastattr{ref}; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 22 | %lastattr = (); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | return if $AUTOLOAD =~ /::DESTROY$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | my ($class) = $AUTOLOAD =~ m/(.*)::/g; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | $AUTOLOAD =~ m/_ATTR_(.*?)_(.*)/ or croak "Can't locate class method '$AUTOLOAD' via package '$class'"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | croak "Attribute handler '$2' doesn't handle $1 attributes"; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | my $builtin = qr/lvalue|locked|unique|shared/; # Method left out on purpose. | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 20 | ▶ | sub _gen_handler_AH_() { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_handler_AH_: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 74 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=20 SCAR=30.2
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 74 | ▶ | _resolve_lastattr if _delayed_name_resolution; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 74 | my ($pkg, $ref, @attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 74 | push @attrs, attributes::get($ref); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 74 | Perlmazing::remove_duplicates(@attrs); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 74 | my (undef, $filename, $linenum) = caller 2; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 74 | foreach (@attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 166 | 75 | ▶ | my ($attr, $data) = /^([a-z_]\w*)(?:[(](.*)[)])?$/is or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 75 | ▶ | if ($attr eq 'ATTR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 21 | ▶ | $data ||= "ANY"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$data ||= "ANY"
MC/DC100%1/1
$data ||= "ANY"
$data
Truth table100%2/2
A
A= $data
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 21 | $raw{$ref} = $data =~ s/\s*,?\s*RAWDATA\s*,?\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 21 | ▶ | $phase{$ref}{BEGIN} = 1 if $data =~ s/\s*,?\s*(BEGIN)\s*,?\s*//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 21 | ▶ | $phase{$ref}{INIT} = 1 if $data =~ s/\s*,?\s*(INIT)\s*,?\s*//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 21 | ▶ | $phase{$ref}{END} = 1 if $data =~ s/\s*,?\s*(END)\s*,?\s*//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 21 | ▶ | $phase{$ref}{CHECK} = 1 if $data =~ s/\s*,?\s*(CHECK)\s*,?\s*// || ! keys %{$phase{$ref}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data =~ s/\s*,?\s*(CHECK)\s*,?\s*// or not keys %{$phase{$ref};}
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};}
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | # Added for cleanup to not pollute next call. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 21 | ▶ | (%lastattr = ()), croak "Can't have two ATTR specifiers on one subroutine" if keys %lastattr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 21 | ▶ | croak "Bad attribute type: ATTR($data)" unless $validtype{$data}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 21 | %lastattr=(pkg=>$pkg,ref=>$ref,type=>$data); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 21 | ▶ | _resolve_lastattr unless _delayed_name_resolution; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 54 | my $type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 54 | my $handler = $pkg->can("_ATTR_${type}_${attr}"); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 54 | ▶ | next unless $handler; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 54 | my $decl = [$pkg, $ref, $attr, $data, $raw{$handler}, $phase{$handler}, $filename, $linenum]; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 54 | foreach my $gphase (@global_phases) { | |||||||||||||||||||||||||||||||||||||||||
| 186 | _apply_handler_AH_($decl,$gphase) | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 216 | ▶ | if $global_phases{$gphase} <= $global_phase; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 54 | ▶ | if ($global_phase != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | # if _gen_handler_AH_ is being called after | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # CHECK it's for a lexical, so make sure | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # it didn't want to run anything later | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 35 | local $Carp::CarpLevel = 2; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 35 | ▶ | carp "Won't be able to apply END handler" if $phase{$handler}{END}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 19 | push @declarations, $decl | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 74 | $_ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 73 | ▶ | return grep {defined && !/$builtin/} @attrs; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && !/$builtin/
MC/DC0%0/2
defined $_ && !/$builtin/
defined $_
!/$builtin/
Truth table33%1/3
A && not(B)
A= defined $_B= !/$builtin/
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 20 | } | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 181 | ▶ | sub _apply_handler_AH_ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_handler_AH_: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 181 | my ($declaration, $phase) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 181 | my ($pkg, $ref, $attr, $data, $raw, $handlerphase, $filename, $linenum) = @$declaration; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 181 | ▶ | return unless $handlerphase->{$phase}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | # print STDERR "Handling $attr on $ref in $phase with [$data]\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 53 | my $type = ref $ref; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 53 | my $handler = "_ATTR_${type}_${attr}"; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 53 | my $sym = findsym($pkg, $ref); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 53 | ▶ | $sym ||= $type eq 'CODE' ? 'ANON' : 'LEXICAL'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sym ||= $type eq "CODE" ? "ANON" : "LEXICAL"
MC/DC0%0/2
$sym ||= $type eq "CODE" ? "ANON" : "LEXICAL"
$sym
$type eq "CODE" ? "ANON" : "LEXICAL"
Truth table0%0/3
A ||= B
A= $symB= $type eq "CODE" ? "ANON" : "LEXICAL"
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 53 | ▶ | if (!$raw && defined($data)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $raw and defined $data
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
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 45 | ▶ | if ($data ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 45 | ▶ | my $evaled = eval( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | " | ||||||||||||||||||||||||||||||||||||||||||
| 219 | package $pkg; | ||||||||||||||||||||||||||||||||||||||||||
| 220 | no warnings; | ||||||||||||||||||||||||||||||||||||||||||
| 221 | no strict; | ||||||||||||||||||||||||||||||||||||||||||
| 222 | local \$SIG{__WARN__}=sub{die}; | ||||||||||||||||||||||||||||||||||||||||||
| 223 | [$data] | ||||||||||||||||||||||||||||||||||||||||||
| 224 | " | ||||||||||||||||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 45 | ▶ | $data = $evaled unless $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $data = undef; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | $pkg->$handler( | ||||||||||||||||||||||||||||||||||||||||||
| 232 | $sym, | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 53 | ▶ | (ref $sym eq 'GLOB' ? *{$sym}{ref $ref} || $ref : $ref), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
*{$sym;}{ref $ref} or $ref
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
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | $attr, | ||||||||||||||||||||||||||||||||||||||||||
| 235 | $data, | ||||||||||||||||||||||||||||||||||||||||||
| 236 | $phase, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | $filename, | ||||||||||||||||||||||||||||||||||||||||||
| 238 | $linenum, | ||||||||||||||||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 53 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | ▶ | no warnings 'void'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | ▶ | CHECK { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CHECK: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | $global_phase++; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | _resolve_lastattr if _delayed_name_resolution; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | foreach my $decl (@declarations) { | |||||||||||||||||||||||||||||||||||||||||
| 249 | 19 | _apply_handler_AH_($decl, 'CHECK'); | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | ▶ | INIT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
INIT: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | $global_phase++; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | foreach my $decl (@declarations) { | |||||||||||||||||||||||||||||||||||||||||
| 255 | 19 | _apply_handler_AH_($decl, 'INIT'); | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | ▶ | END { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | $global_phase++; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | foreach my $decl (@declarations) { | |||||||||||||||||||||||||||||||||||||||||
| 263 | 19 | _apply_handler_AH_($decl, 'END'); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | __END__ | ||||||||||||||||||||||||||||||||||||||||||