| 1 | package Module::Pragma; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.010_000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | #use Smart::Comments; # for debugging | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | my %register = (); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub import | ||||||||||||||||||||||||||||
| 15 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 16 | 12 | my $class = shift @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 12 | ▶ | return if $class eq __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 10 | ▶ | @_ = $class->default_import() unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | ### import: \@_, join ' ', caller | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 9 | $class->check_exclusive(@_); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 8 | $^H{$class} |= $class->pack_tags(@_); | |||||||||||||||||||||||||||
| 27 | 8 | $^H{$class} &= ~$class->pack_tags( $class->exclusive_tags(@_) ); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub unimport | ||||||||||||||||||||||||||||
| 31 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 32 | 5 | my $class = shift @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | ▶ | return if $class eq __PACKAGE__; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | ### unimport: \@_, join ' ', caller | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | ▶ | if(@_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 2 | $class->check_exclusive(@_); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | $^H{$class} |= $class->pack_tags( $class->exclusive_tags(@_) ); | |||||||||||||||||||||||||||
| 42 | 2 | $^H{$class} &= ~$class->pack_tags(@_); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else{ | ||||||||||||||||||||||||||||
| 45 | 2 | delete $^H{$class}; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub enabled | ||||||||||||||||||||||||||||
| 50 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
enabled: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 24 | my $class = shift @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 24 | my $bits = $class->hint(1); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 24 | ▶ | $bits &= $class->pack_tags(@_) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 24 | ▶ | return wantarray ? $class->unpack_tags($bits) : $bits; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub hint | ||||||||||||||||||||||||||||
| 61 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
hint: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 24 | my($class, $level) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 24 | my $hint_hash; | |||||||||||||||||||||||||||
| 65 | my $bits; | ||||||||||||||||||||||||||||
| 66 | do { | ||||||||||||||||||||||||||||
| 67 | 29 | my $pkg; | |||||||||||||||||||||||||||
| 68 | 29 | ($pkg, $hint_hash) = ( caller ++$level )[0, 10]; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 29 | ▶ | return undef unless defined $pkg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 24 | ▶ | } until defined( $bits = $hint_hash->{$class} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 18 | return $bits; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub unknown_tag | ||||||||||||||||||||||||||||
| 78 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unknown_tag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 2 | my($class, $tag) = @_; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | $class->_die("unknown subpragma '$tag'"); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub default_import | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
default_import: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 1 | my($class) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | $class->_die('requires explicit arguments'); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub _die | ||||||||||||||||||||||||||||
| 93 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_die: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 6 | my $class = shift @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 6 | require Carp; | |||||||||||||||||||||||||||
| 97 | 6 | Carp::croak("$class: ", @_); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub register_tags | ||||||||||||||||||||||||||||
| 102 | 74 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
register_tags: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 74 | my($class, @tags) = @_; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 74 | ▶ | my $map = $register{$class} //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$register{$class} //= {}
MC/DC100%1/1
$register{$class} //= {}
$register{$class}
Truth table100%2/2
A
A= $register{$class}
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 74 | my $bit_ref = \($map->{___bit___}); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 74 | ▶ | while(defined(my $tag = shift @tags)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 83 | ▶ | unless($$bit_ref){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 7 | $$bit_ref = 1; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | else{ | ||||||||||||||||||||||||||||
| 116 | 76 | my $old = $$bit_ref; | |||||||||||||||||||||||||||
| 117 | 76 | $$bit_ref <<= 1; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | #bitmask test | ||||||||||||||||||||||||||||
| 120 | 76 | ▶ | if($$bit_ref == 0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 1 | __PACKAGE__->_die("$tag=($old << 1) is not a valid bitmask (integer overflowed?)"); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 82 | ▶ | if($tag =~ /^___/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 1 | __PACKAGE__->_die("'$tag' is not a valid tag name"); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 81 | ▶ | if(@tags && $tags[0] =~ /^\d+$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@tags and $tags[0] =~ /^\d+$/
MC/DC100%2/2
@tags and $tags[0] =~ /^\d+$/
@tags
$tags[0] =~ /^\d+$/
Truth table100%3/3
A and B
A= @tagsB= $tags[0] =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 130 | 2 | $$bit_ref = int shift @tags; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 81 | $map->{$tag} = $$bit_ref; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 72 | return $$bit_ref; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | sub register_bundle | ||||||||||||||||||||||||||||
| 141 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
register_bundle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 1 | my($class, $bundle, @tags) = @_; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | $register{$class}{':' . $bundle} = $class->pack_tags(@tags); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | sub register_exclusive | ||||||||||||||||||||||||||||
| 148 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
register_exclusive: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 6 | my $class = shift @_; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 6 | ▶ | my $ex = $register{$class}{___ex___} //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$register{$class}{"___ex___"} //= {}
MC/DC100%1/1
$register{$class}{"___ex___"} //= {}
$register{$class}{"___ex___"}
Truth table100%2/2
A
A= $register{$class}{"___ex___"}
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 6 | foreach my $x(@_){ | |||||||||||||||||||||||||||
| 154 | 14 | foreach my $y(@_){ | |||||||||||||||||||||||||||
| 155 | 38 | ▶ | unless($x eq $y){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 24 | push @ {$ex->{$x} }, $y; | |||||||||||||||||||||||||||
| 157 | 24 | $ex->{$x, $y} = 1; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | sub exclusive_tags | ||||||||||||||||||||||||||||
| 164 | 16 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
exclusive_tags: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 16 | my $class = shift @_; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 16 | ▶ | my $ex = $register{$class}{___ex___} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 15 | my @ex_tags; | |||||||||||||||||||||||||||
| 170 | my %seen; | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # expansion and regulation | ||||||||||||||||||||||||||||
| 173 | 15 | foreach my $tag(grep{ $ex->{$_} } map{ $class->unpack_tags( $class->tag($_) ) } @_) | |||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||
| 175 | push @ex_tags, | ||||||||||||||||||||||||||||
| 176 | 16 | grep{ !$seen{$_}++ } # uniq | |||||||||||||||||||||||||||
| 177 | 16 | map { $class->unpack_tags( $class->tag($_) ) } | |||||||||||||||||||||||||||
| 178 | 11 | @{ $ex->{$tag} }; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 15 | return @ex_tags; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | sub check_exclusive | ||||||||||||||||||||||||||||
| 184 | 11 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check_exclusive: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 185 | 11 | my $class = shift @_; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 11 | ▶ | my $ex = $register{$class}{___ex___} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | # check whether these are exclusive | ||||||||||||||||||||||||||||
| 190 | 10 | foreach my $x(@_){ | |||||||||||||||||||||||||||
| 191 | 10 | foreach my $y(@_){ | |||||||||||||||||||||||||||
| 192 | 11 | ▶ | $class->_die("'$x' and '$y' are exclusive mutually") if $ex->{$x, $y}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | sub tag | ||||||||||||||||||||||||||||
| 198 | 421 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
tag: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 421 | my($class, $tag) = @_; | |||||||||||||||||||||||||||
| 200 | 421 | ▶ | return $register{$class}{$tag} // $class->unknown_tag($tag); | ||||||||||||||||||||||||||
|
Condition100%3/3
$register{$class}{$tag} // $class->unknown_tag($tag)
MC/DC0%0/2
$register{$class}{$tag} // $class->unknown_tag($tag)
$register{$class}{$tag}
$class->unknown_tag($tag)
Truth table66%2/3
A // B
A= $register{$class}{$tag}B= $class->unknown_tag($tag)
| |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | sub tags | ||||||||||||||||||||||||||||
| 204 | 48 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
tags: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | 48 | my($class) = @_; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 48 | ▶ | my $map = $register{$class} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 47 | ▶ | return grep{ not( /^:/ or /^__/ ) } keys %$map; | ||||||||||||||||||||||||||
|
Condition100%3/3
/^:/ || /^__/
MC/DC100%2/2
/^:/ || /^__/
/^:/
/^__/
Truth table100%3/3
A || B
A= /^:/B= /^__/
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub pack_tags | ||||||||||||||||||||||||||||
| 214 | 40 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
pack_tags: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 40 | my $class = shift @_; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 40 | my $bits = 0; | |||||||||||||||||||||||||||
| 218 | 40 | foreach my $tag(@_){ | |||||||||||||||||||||||||||
| 219 | 51 | $bits |= $class->tag($tag); | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | 39 | return $bits; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | sub unpack_tags | ||||||||||||||||||||||||||||
| 224 | 46 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unpack_tags: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 46 | my($class, $bits) = @_; | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 46 | ▶ | return unless defined $bits; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 40 | ▶ | return grep{ $class->tag($_) & $bits or $class->tag($_) == $bits } $class->tags; | ||||||||||||||||||||||||||
|
Condition100%3/3
$class->tag($_) & $bits || $class->tag($_) == $bits
MC/DC100%2/2
$class->tag($_) & $bits || $class->tag($_) == $bits
$class->tag($_) & $bits
$class->tag($_) == $bits
Truth table100%3/3
A || B
A= $class->tag($_) & $bitsB= $class->tag($_) == $bits
| |||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 3 | 1; | |||||||||||||||||||||||||||
| 233 | __END__ | ||||||||||||||||||||||||||||