| 1 | package vars; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | use 5.006; | ||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | our $VERSION = '1.05'; | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | use warnings::register; | ||||||||||||||||||||||||||||||||||
| 8 | use strict qw(vars subs); | ||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | sub import { | ||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | my $callpack = caller; | ||||||||||||||||||||||||||||||||
|
Subroutine
import: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||
| 12 | 0 | my (undef, @imports) = @_; | |||||||||||||||||||||||||||||||||
| 13 | 0 | my ($sym, $ch); | |||||||||||||||||||||||||||||||||
| 14 | 0 | foreach (@imports) { | |||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | if (($ch, $sym) = /^([\$\@\%\*\&])(.+)/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | if ($sym =~ /\W/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 17 | # time for a more-detailed check-up | ||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if ($sym =~ /^\w+[[{].*[]}]$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 19 | 0 | require Carp; | |||||||||||||||||||||||||||||||||
| 20 | 0 | Carp::croak("Can't declare individual elements of hash or array"); | |||||||||||||||||||||||||||||||||
| 21 | ▶ | } elsif (warnings::enabled() and length($sym) == 1 and $sym !~ tr/a-zA-Z//) { | |||||||||||||||||||||||||||||||||
|
Condition0%0/6
warnings::enabled() and length $sym == 1 and not $sym =~ tr/A-Za-z//
warnings::enabled() and length $sym == 1
MC/DC0%0/3
warnings::enabled() and length $sym == 1 and not $sym =~ tr/A-Za-z//
warnings::enabled()
length $sym == 1
not $sym =~ tr/A-Za-z//
Truth table0%0/4
A and B and not(C)
A= warnings::enabled()B= length $sym == 1C= not $sym =~ tr/A-Za-z//
| |||||||||||||||||||||||||||||||||||
| 22 | 0 | warnings::warn("No need to declare built-in vars"); | |||||||||||||||||||||||||||||||||
| 23 | } elsif (($^H & strict::bits('vars'))) { | ||||||||||||||||||||||||||||||||||
| 24 | 0 | require Carp; | |||||||||||||||||||||||||||||||||
| 25 | 0 | Carp::croak("'$_' is not a valid variable name under strict vars"); | |||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $sym = "${callpack}::$sym" unless $sym =~ /::/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | *$sym = | ||||||||||||||||||||||||||||||||||
| 30 | ( $ch eq "\$" ? \$$sym | ||||||||||||||||||||||||||||||||||
| 31 | : $ch eq "\@" ? \@$sym | ||||||||||||||||||||||||||||||||||
| 32 | : $ch eq "\%" ? \%$sym | ||||||||||||||||||||||||||||||||||
| 33 | : $ch eq "\*" ? \*$sym | ||||||||||||||||||||||||||||||||||
| 34 | : $ch eq "\&" ? \&$sym | ||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | : do { | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | require Carp; | |||||||||||||||||||||||||||||||||
| 37 | 0 | Carp::croak("'$_' is not a valid variable name"); | |||||||||||||||||||||||||||||||||
| 38 | }); | ||||||||||||||||||||||||||||||||||
| 39 | } else { | ||||||||||||||||||||||||||||||||||
| 40 | 0 | require Carp; | |||||||||||||||||||||||||||||||||
| 41 | 0 | Carp::croak("'$_' is not a valid variable name"); | |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 1; | ||||||||||||||||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||||||||||||||||