blib/lib/Test2/V1.pm

filter: Statementstmt 96.9% 128 / 132 Branchbran 82.0% 64 / 78 Conditioncond 60.4% 29 / 48 MC/DCmcdc 23.0% 6 / 26 Subroutinesub 94.1% 16 / 17 Podpod n/a totaltotal 80.7% 243 / 301 CC 62 SCAR 26.4
CC
62
Cov
86%
_parse_args
26.1
import
17.4
_build_exports
10.1
CRAP 14.0
« blib/lib/Test2/Tools/ClassicCompare.pm ↑ Summary blib/lib/Test2/Util/Stash.pm »
1 package Test2::V1;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 our $VERSION = '1.302226';
6  
7 4 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use Test2::V1::Base();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Test2::V1::Handle();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Test2::Plugin::ExitSummary();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Test2::Plugin::SRand();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Test2::Plugin::UTF8();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Test2::Tools::Target();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # Magic reference to check against later
18 4 my $SET = \'set';
19  
20 # Lists of pragmas and plugins
21 4 my @PRAGMAS = qw/strict warnings/;
22 4 my @PLUGINS = qw/utf8 srand summary target/;
23  
24 13 ▶sub import {
Subroutine import: called CC=17 SCAR=28.5
25 13 my $class = shift;
26  
27 13 my $caller = caller;
28  
29 croak "Got One or more undefined arguments, this usually means you passed in a single-character flag like '-p' without quoting it, which conflicts with the -p builtin"
30 13 ▶ if grep { !defined($_) } @_;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} @_ 1 12 13
31  
32 12 my ($requested_exports, $options) = $class->_parse_args(\@_);
33  
34 12 my $pragmas = $class->_compute_pragmas($options);
35 12 my $plugins = $class->_compute_plugins($options);
36  
37 12 my ($handle_name, $handle) = $class->_build_handle($options);
38 12 my $ns = $handle->HANDLE_NAMESPACE;
39  
40 12 ▶ unshift @$requested_exports => $handle->HANDLE_SUBS() if delete $options->{'-import'};
Branch: 1 branch
BranchTrueFalseTotal
if delete $options->{"-import"} 6 6 12
41  
42 12 ▶ unshift @$requested_exports => grep { my $p = prototype($ns->can($_)); $p && $p =~ '&' } $handle->HANDLE_SUBS() if delete $options->{'-x'};
Branch: 1 branch
BranchTrueFalseTotal
if delete $options->{"-x"} 2 10 12
Condition100%3/3
$p && $p =~ /&/
!ll&&!rl&&r
807432
MC/DC100%2/2
$p && $p =~ /&/
$p $p =~ /&/
Truth table100%3/3
A && B
A= $pB= $p =~ /&/
ABresult
0X0
100
111
43  
44 12 my $exports = $class->_build_exports($handle, $requested_exports);
45 12 ▶ unless (delete $options->{'-no-T2'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (delete $options->{"-no-T2"}) 9 3 12
46 9 my $h = $handle;
47 0 ▶ $exports->{$handle_name} = sub() { $h };
Subroutine __ANON__: not called CC=1 SCAR=1.2
48 }
49  
50 12 ▶ croak "Unknown option(s): " . join(', ', sort keys %$options) if keys %$options;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$options 0 12 12
51  
52 12 ▶ strict->import() if $pragmas->{strict};
Branch: 1 branch
BranchTrueFalseTotal
if $pragmas->{"strict"} 4 8 12
53 12 ▶ 'warnings'->import() if $pragmas->{warnings};
Branch: 1 branch
BranchTrueFalseTotal
if $pragmas->{"warnings"} 4 8 12
54 12 ▶ Test2::Plugin::UTF8->import() if $plugins->{utf8};
Branch: 1 branch
BranchTrueFalseTotal
if $plugins->{"utf8"} 4 8 12
55 12 ▶ Test2::Plugin::ExitSummary->import() if $plugins->{summary};
Branch: 1 branch
BranchTrueFalseTotal
if $plugins->{"summary"} 12 0 12
56  
57 12 ▶ if (my $set = $plugins->{srand}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $set = $plugins->{"srand"}) 4 8 12
58 4 ▶ Test2::Plugin::SRand->import((ref($set) && "$set" ne "$SET") ? $set->{seed} : ());
Branch: 1 branch
BranchTrueFalseTotal
ref $set && "$set" ne "$SET" ? : 0 4 4
Condition33%1/3
ref $set and "$set" ne "$SET"
!ll&&!rl&&r
040
MC/DC0%0/2
ref $set and "$set" ne "$SET"
ref $set "$set" ne "$SET"
Truth table33%1/3
A and B
A= ref $setB= "$set" ne "$SET"
ABresult
0X0
100
111
59 }
60  
61 12 ▶ if (my $target = $plugins->{target}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $target = $plugins->{"target"}) 4 8 12
62 4 ▶ Test2::Tools::Target->import_into($caller, $plugins->{target}) unless "$target" eq "$SET";
Branch: 1 branch
BranchTrueFalseTotal
unless "$target" eq "$SET" 4 0 4
63 }
64  
65 12 for my $exp (keys %$exports) {
66 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
67 599 *{"$caller\::$exp"} = $exports->{$exp};
68 }
69 }
70  
71 12 ▶sub _build_exports {
Subroutine _build_exports: called CC=10 SCAR=23.2
72 12 my $class = shift;
73 12 my ($handle, $requested) = @_;
74  
75 12 my %exports;
76  
77 12 ▶ while (my $exp = shift @$requested) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exp = shift @$requested) 594 12 606
78 594 ▶ if ($exp =~ m/^!(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exp =~ /^!(.+)$/) 2 592 594
79 2 delete $exports{$1};
80 2 next;
81 }
82  
83 592 ▶ my $code = $handle->HANDLE_NAMESPACE->can($exp) or croak "requested export '$exp' is not available";
Branch: 1 branch
BranchTrueFalseTotal
my $code = $handle->HANDLE_NAMESPACE->can($exp) or croak("requested export '${exp}' is not available") 592 0 592
84  
85 592 ▶ my $args = shift @$requested if @$requested && ref($requested->[0]) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if @$requested and ref $requested->[0] eq "HASH" 1 591 592
Condition100%3/3
@$requested and ref $requested->[0] eq "HASH"
!ll&&!rl&&r
65851
MC/DC100%2/2
@$requested and ref $requested->[0] eq "HASH"
@$requested ref $requested->[0] eq "HASH"
Truth table100%3/3
A and B
A= @$requestedB= ref $requested->[0] eq "HASH"
ABresult
0X0
100
111
86  
87 592 my $name = $exp;
88 592 ▶ if ($args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args) 1 591 592
89 1 ▶ $name = delete $args->{-as} if $args->{-as};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"-as"} 1 0 1
90 1 ▶ $name = delete($args->{-prefix}) . $name if $args->{-prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"-prefix"} 0 1 1
91 1 ▶ $name = $name . delete($args->{-postfix}) if $args->{-postfix};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"-postfix"} 0 1 1
92 }
93  
94 592 $exports{$name} = $code;
95 }
96  
97 12 return \%exports;
98 }
99  
100 12 ▶sub _build_handle {
Subroutine _build_handle: called CC=4 SCAR=15.0
101 12 my $class = shift;
102 12 my ($options) = @_;
103  
104 12 ▶ my $handle_opts = delete $options->{'-T2'} || {};
Condition50%1/2
delete $options->{'-T2'} || {}
l!l
012
MC/DC0%0/1
delete $options->{'-T2'} || {}
delete $options->{'-T2'}
Truth table50%1/2
A
A= delete $options->{'-T2'}
Aresult
11
00
105 12 ▶ my $handle_name = delete $handle_opts->{'-as'} || delete $handle_opts->{'as'} || 'T2';
Condition40%2/5
delete $handle_opts->{'-as'} || delete $handle_opts->{'as'} || 'T2'
l!l
012
delete $handle_opts->{"-as"} or delete $handle_opts->{"as"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
delete $handle_opts->{'-as'} || delete $handle_opts->{'as'} || 'T2'
delete $handle_opts->{"-as"} delete $handle_opts->{"as"}
Truth table33%1/3
A or B
A= delete $handle_opts->{"-as"}B= delete $handle_opts->{"as"}
ABresult
1X1
011
000
106 12 my $handle = Test2::V1::Handle->new(%$handle_opts);
107  
108 12 return ($handle_name, $handle);
109 }
110  
111 12 ▶sub _compute_plugins {
Subroutine _compute_plugins: called CC=7 SCAR=19.5
112 12 my $class = shift;
113 12 my ($options) = @_;
114  
115 12 my $plugins = { summary => $SET };
116  
117 12 ▶ if (my $plug = delete $options->{'-plugins'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $plug = delete $options->{"-plugins"}) 3 9 12
118 3 ▶ if (ref($plug)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plug) { } 0 3 3
119 0 $plugins = $plug;
120 }
121 else {
122 3 $plugins = { map { $_ => $SET } @PLUGINS };
123 }
124 }
125  
126 12 for my $plug (@PLUGINS) {
127 48 my $set = delete $options->{"-$plug"};
128 48 ▶ $plugins->{$plug} = $set if $set && "$set" ne "$SET";
Branch: 1 branch
BranchTrueFalseTotal
if $set and "$set" ne "$SET" 4 44 48
Condition100%3/3
$set and "$set" ne "$SET"
!ll&&!rl&&r
4224
MC/DC100%2/2
$set and "$set" ne "$SET"
$set "$set" ne "$SET"
Truth table100%3/3
A and B
A= $setB= "$set" ne "$SET"
ABresult
0X0
100
111
129 48 ▶ $plugins->{$plug} = $set unless defined $plugins->{$plug};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plugins->{$plug} 26 22 48
130 }
131  
132 12 return $plugins;
133 }
134  
135 12 ▶sub _compute_pragmas {
Subroutine _compute_pragmas: called CC=8 SCAR=21.6
136 12 my $class = shift;
137 12 my ($options) = @_;
138  
139 12 my $pragmas = {};
140 12 ▶ if (my $prag = delete $options->{'-pragmas'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prag = delete $options->{"-pragmas"}) 3 9 12
141 3 ▶ if (ref($prag) && "$prag" ne "$SET") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $prag and "$prag" ne "$SET") { } 0 3 3
Condition33%1/3
ref $prag and "$prag" ne "$SET"
!ll&&!rl&&r
300
MC/DC0%0/2
ref $prag and "$prag" ne "$SET"
ref $prag "$prag" ne "$SET"
Truth table33%1/3
A and B
A= ref $pragB= "$prag" ne "$SET"
ABresult
0X0
100
111
142 0 $pragmas = $prag;
143 }
144 else {
145 3 $pragmas = { map { $_ => $SET } @PRAGMAS };
146 }
147 }
148  
149 12 for my $prag (@PRAGMAS) {
150 24 my $set = delete $options->{"-$prag"};
151 24 ▶ $pragmas->{$prag} = $set if $set && "$set" ne "$SET";
Branch: 1 branch
BranchTrueFalseTotal
if $set and "$set" ne "$SET" 0 24 24
Condition66%2/3
$set and "$set" ne "$SET"
!ll&&!rl&&r
2220
MC/DC0%0/2
$set and "$set" ne "$SET"
$set "$set" ne "$SET"
Truth table66%2/3
A and B
A= $setB= "$set" ne "$SET"
ABresult
0X0
100
111
152 24 ▶ $pragmas->{$prag} = $set unless defined $pragmas->{$prag};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pragmas->{$prag} 18 6 24
153 }
154  
155 12 return $pragmas
156 }
157  
158 12 ▶sub _parse_args {
Subroutine _parse_args: called CC=21 SCAR=32.6
159 12 my $class = shift;
160 12 my ($args) = @_;
161  
162 12 my (@exports, %options);
163  
164 12 ▶ while (my $arg = shift @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift @$args) 24 12 36
165 24 ▶ $arg = '-T2' if $arg eq 'T2';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "T2" 0 24 24
166 24 ▶ push @exports => $arg and next unless substr($arg, 0, 1) eq '-';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($arg, 0, 1) eq "-" 5 19 24
Condition75%3/4
substr($arg, 0, 1) eq '-' || push(@exports, $arg) && (next)
l!l
195
push @exports, $arg and next
!ll
05
MC/DC0%0/2
substr($arg, 0, 1) eq '-' || push(@exports, $arg) && (next)
substr($arg, 0, 1) eq '-' push @exports, $arg
Truth table66%2/3
A || B
A= substr($arg, 0, 1) eq '-'B= push @exports, $arg
ABresult
1X1
011
000
167 19 ▶ $options{$arg} = shift @$args and next if $arg eq '-target';
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "-target" 4 15 19
Condition75%3/4
$arg eq '-target' && (($options{$arg} = shift @$args) && (next))
!ll
154
$options{$arg} = shift @$args and next
!ll
04
MC/DC0%0/2
$arg eq '-target' && (($options{$arg} = shift @$args) && (next))
$arg eq '-target' $options{$arg} = shift @$args
Truth table33%1/3
A && B
A= $arg eq '-target'B= $options{$arg} = shift @$args
ABresult
0X0
100
111
168 15 ▶ $options{$arg} = (@$args && (ref($args->[0]) || "$args->[0]" eq "1" || "$args->[0]" eq "0")) ? shift @$args : $SET;
Branch: 1 branch
BranchTrueFalseTotal
@$args && (ref $args->[0] || "$args->[0]" eq '1' || "$args->[0]" eq '0') ? : 0 15 15
Condition44%4/9
@$args and ref $args->[0] || "$args->[0]" eq 1 || "$args->[0]" eq 0
!ll&&!rl&&r
5100
ref $args->[0] or "$args->[0]" eq 1 or "$args->[0]" eq 0
l!l&&r!l&&!r
0010
ref $args->[0] or "$args->[0]" eq 1
l!l&&r!l&&!r
0010
MC/DC0%0/4
@$args and ref $args->[0] || "$args->[0]" eq 1 || "$args->[0]" eq 0
@$args ref $args->[0] "$args->[0]" eq 1 "$args->[0]" eq 0
Truth table40%2/5
A and B or C or D
A= @$argsB= ref $args->[0]C= "$args->[0]" eq 1D= "$args->[0]" eq 0
ABCDresult
0XXX0
10000
11XX1
101X1
10011
169 }
170  
171 12 ▶ if (my $inc = delete $options{'-include'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inc = delete $options{"-include"}) 0 12 12
172 0 $options{'-T2'}->{include} = $inc;
173 }
174  
175 12 for my $key (keys %options) {
176 19 ▶ next unless $key =~ m/^-([ipP]{1,3})$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /^-([ipP]{1,3})$/ 15 4 19
177 4 delete $options{$key};
178 4 for my $flag (split //, $1) {
179 10 $options{"-$flag"} = 1;
180 }
181 }
182  
183 12 ▶ $options{'-import'} ||= 1 if delete $options{'-i'};
Branch: 1 branch
BranchTrueFalseTotal
if delete $options{"-i"} 4 8 12
Condition50%1/2
$options{"-import"} ||= 1
l!l
04
MC/DC0%0/1
$options{"-import"} ||= 1
$options{"-import"}
Truth table50%1/2
A
A= $options{"-import"}
Aresult
11
00
184 12 ▶ $options{'-pragmas'} ||= 1 if delete $options{'-p'};
Branch: 1 branch
BranchTrueFalseTotal
if delete $options{"-p"} 3 9 12
Condition50%1/2
$options{"-pragmas"} ||= 1
l!l
03
MC/DC0%0/1
$options{"-pragmas"} ||= 1
$options{"-pragmas"}
Truth table50%1/2
A
A= $options{"-pragmas"}
Aresult
11
00
185 12 ▶ $options{'-plugins'} ||= 1 if delete $options{'-P'};
Branch: 1 branch
BranchTrueFalseTotal
if delete $options{"-P"} 3 9 12
Condition50%1/2
$options{"-plugins"} ||= 1
l!l
03
MC/DC0%0/1
$options{"-plugins"} ||= 1
$options{"-plugins"}
Truth table50%1/2
A
A= $options{"-plugins"}
Aresult
11
00
186  
187 12 return (\@exports, \%options);
188 }
189  
190 4 1;
191  
192 __END__
« blib/lib/Test2/Tools/ClassicCompare.pm ↑ Summary blib/lib/Test2/Util/Stash.pm »