blib/lib/Acme/CXW/vars/i.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 28 / 28 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 89 / 89 CC 17 SCAR 27.3
CC
17
Cov
100%
import
17.0
BEGIN
1.0
BEGIN
1.0
CRAP 15.3
↑ Summary
1 # I basically took vars.pm, and turned it into vars/i.pm
2
3 package Acme::CXW::vars::i;
4 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 3 our $VERSION = '1.04'; # TRIAL
7
8 # yuck
9 =for IT DOESN'T WORK nor is it important (try perl -Mstrict -Mwarnings=all -We"use vars q[$a];")
10 BEGIN {
11 eval q{
12 use warnings::register;
13 };
14 eval q{
15 sub warnings::enabled { return $^W; }
16 } if $@;
17 }
18 =cut
19
20 3 ▶use strict qw(vars subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
21
22 23 ▶sub import {
Subroutine import: called CC=17 SCAR=28.3
23 23 ▶ return if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 3 20 23
24 20 my( $pack, $var, @value ) = @_;
25 20 my $callpack = caller;
26
27 20 my %stuff;
28
29 20 ▶ if( not @value ){
Branch: 1 branch
BranchTrueFalseTotal
if (not @value) { } 4 16 20
30 4 ▶ if( ref $var ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $var) { } 3 1 4
31 3 %stuff = @$var;
32 } else {
33 1 return; # No value given --- no-op; not an error.
34 }
35 } else {
36 16 %stuff = ( $var, [@value] );
37 }
38
39 19 for my $k( keys %stuff ){
40 20 $var = $k;
41 20 ▶ if( ref $stuff{$k} eq 'ARRAY' ){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $stuff{$k} eq 'ARRAY') { } 17 3 20
elsif (ref $stuff{$k} eq 'HASH') { } 1 2 3
42 17 @value = @{ $stuff{$k} };
43 }
44 elsif( ref $stuff{$k} eq 'HASH' ){
45 1 @value = %{ $stuff{$k} };
46 }
47 else {
48 2 @value = $stuff{$k};
49 }
50
51
52 20 ▶ if( my( $ch, $sym ) = $var =~ /^([\$\@\%\*\&])(.+)$/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (() = $var =~ /^([\$\@\%\*\&])(.+)$/) { } 18 2 20
53 18 ▶ if( $sym !~ /^(\w+(::|'))+\w+$/ && $sym =~ /\W|(^\d+$)/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (not $sym =~ /^(\w+(::|'))+\w+$/ and $sym =~ /\W|(^\d+$)/) 8 10 18
Condition100%3/3
not $sym =~ /^(\w+(::|'))+\w+$/ and $sym =~ /\W|(^\d+$)/
!ll&&!rl&&r
198
MC/DC100%2/2
not $sym =~ /^(\w+(::|'))+\w+$/ and $sym =~ /\W|(^\d+$)/
not $sym =~ /^(\w+(::|'))+\w+$/ $sym =~ /\W|(^\d+$)/
Truth table100%3/3
not(A) and B
A= not $sym =~ /^(\w+(::|'))+\w+$/B= $sym =~ /\W|(^\d+$)/
ABresult
0X0
100
111
54 # ^^ Skip fully-qualified names ^^ Check special names
55
56 # A variable name we can't or won't handle
57 8 require Carp;
58
59 8 ▶ if( $sym =~ /^\w+[[{].*[]}]$/ ){
Branch: 2 branches
BranchTrueFalseTotal
if ($sym =~ /^\w+[[{].*[]}]$/) { } 2 6 8
elsif ($sym =~ /^(\d+|\W|\^[\[\]A-Z\^_\?]|\{\^[a-zA-Z0-9]+\})$/) { } 5 1 6
60 2 Carp::croak("Can't declare individual elements of hash or array");
61 }
62 elsif( $sym =~ /^(\d+|\W|\^[\[\]A-Z\^_\?]|\{\^[a-zA-Z0-9]+\})$/ ){
63 5 Carp::croak("Refusing to initialize special variable $ch$sym");
64 }
65 else {
66 1 Carp::croak("I can't recognize $ch$sym as a variable name");
67 }
68 }
69
70 10 ▶ $sym = "${callpack}::$sym" unless $sym =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sym =~ /::/ 9 1 10
71
72 10 ▶ if( $ch eq '$' ){
Branch: 4 branches
BranchTrueFalseTotal
if ($ch eq '$') { } 4 6 10
elsif ($ch eq '@') { } 2 4 6
elsif ($ch eq '%') { } 2 2 4
elsif ($ch eq '*') { } 1 1 2
73 4 *{$sym} = \$$sym;
74 4 (${$sym}) = @value;
75 }
76 elsif( $ch eq '@' ){
77 2 *{$sym} = \@$sym;
78 2 (@{$sym}) = @value;
79 }
80 elsif( $ch eq '%' ){
81 2 *{$sym} = \%$sym;
82 2 (%{$sym}) = @value;
83 }
84 elsif( $ch eq '*' ){
85 1 *{$sym} = \*$sym;
86 1 (*{$sym}) = shift @value;
87 }
88 else { # $ch eq '&'; guaranteed by the regex above.
89 1 *{$sym} = shift @value;
90 }
91 # There is no else, because the regex above guarantees
92 # that $ch has one of the values we tested.
93
94 } else { # Name didn't match the regex above
95 2 require Carp;
96 2 Carp::croak("'$var' is not a valid variable name");
97 }
98 }
99 };
100
101 3 1;
102 __END__
↑ Summary