blib/lib/vars/i.pm

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