blib/lib/Test2/Workflow/Task.pm

filter: Statementstmt 88.1% 82 / 93 Branchbran 60.5% 23 / 38 Conditioncond 40.0% 14 / 35 MC/DCmcdc 22.7% 5 / 22 Subroutinesub 94.1% 16 / 17 Podpod 0.0% 0 / 5 totaltotal 66.6% 140 / 210 CC 33 SCAR 34.5
CC
33
Cov
72%
filter
63.1
verify_scaffold
6.7
init
6.5
CRAP 31.5
« blib/lib/Test2/IPC.pm ↑ Summary blib/lib/Test2/Workflow/Runner.pm »
1 package Test2::Workflow::Task;
2 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 40 our $VERSION = '1.302226';
6  
7 40 ▶use Test2::API();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 40 ▶use Test2::Event::Exception();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 40 ▶use List::Util qw/min max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 40 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 40 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 40 our @CARP_NOT = qw/Test2::Util::HashBase/;
14  
15 40 ▶use base 'Test2::Workflow::BlockBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 40 ▶use Test2::Util::HashBase qw/name flat async iso todo skip scaffold events is_root/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 40 for my $attr (FLAT, ISO, ASYNC, TODO, SKIP, SCAFFOLD) {
19 240 my $old = __PACKAGE__->can("set_$attr");
20 90 ▶ my $new = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
21 90 my $self = shift;
22 90 my $out = $self->$old(@_);
23 90 $self->verify_scaffold;
24 90 return $out;
25 240 };
26  
27 40 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 40 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 240 *{"set_$attr"} = $new;
30 }
31  
32 712 ▶sub init {
Subroutine init: called CC=6 SCAR=18.7
Pod undocumented
33 712 my $self = shift;
34  
35 712 ▶ $self->{+EVENTS} ||= [];
Condition100%2/2
$self->{"events"} ||= []
l!l
67645
MC/DC100%1/1
$self->{"events"} ||= []
$self->{"events"}
Truth table100%2/2
A
A= $self->{"events"}
Aresult
11
00
36  
37 {
38 712 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
39 712 $self->SUPER::init();
40 }
41  
42 $self->throw("the 'name' attribute is required")
43 712 ▶ unless $self->{+NAME};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"name"} 0 712 712
44  
45 $self->throw("the 'flat' attribute cannot be combined with 'iso' or 'async'")
46 712 ▶ if $self->{+FLAT} && ($self->{+ISO} || $self->{+ASYNC});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"flat"} and $self->{"iso"} || $self->{"async"} 0 712 712
Condition50%3/6
$self->{"flat"} and $self->{"iso"} || $self->{"async"}
!ll&&!rl&&r
613990
$self->{"iso"} or $self->{"async"}
l!l&&r!l&&!r
0099
MC/DC0%0/3
$self->{"flat"} and $self->{"iso"} || $self->{"async"}
$self->{"flat"} $self->{"iso"} $self->{"async"}
Truth table50%2/4
A and B or C
A= $self->{"flat"}B= $self->{"iso"}C= $self->{"async"}
ABCresult
0XX0
1000
11X1
1011
47  
48 712 $self->set_subname($self->package . "::<$self->{+NAME}>");
49  
50 712 $self->verify_scaffold;
51 }
52  
53 144 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
54 144 my $self = shift;
55 144 return bless {%$self}, blessed($self);
56 }
57  
58 802 ▶sub verify_scaffold {
Subroutine verify_scaffold: called CC=6 SCAR=19.0
Pod undocumented
59 802 my $self = shift;
60  
61 802 ▶ return unless $self->{+SCAFFOLD};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"scaffold"} 689 113 802
62  
63 croak "The 'flat' attribute must be true for scaffolding"
64 113 ▶ if defined($self->{+FLAT}) && !$self->{+FLAT};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"flat"} and not $self->{"flat"} 0 113 113
Condition33%1/3
defined $self->{"flat"} and not $self->{"flat"}
!ll&&!rl&&r
11300
MC/DC0%0/2
defined $self->{"flat"} and not $self->{"flat"}
defined $self->{"flat"} not $self->{"flat"}
Truth table33%1/3
A and not(B)
A= defined $self->{"flat"}B= not $self->{"flat"}
ABresult
0X0
100
111
65  
66 113 $self->{+FLAT} = 1;
67  
68 113 for my $attr (ISO, ASYNC, TODO, SKIP) {
69 croak "The '$attr' attribute cannot be used on scaffolding"
70 452 ▶ if $self->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$attr} 0 452 452
71 }
72 }
73  
74 0 ▶sub exception {
Subroutine exception: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my $self = shift;
76 0 my ($err) = @_;
77  
78 0 my $hub = Test2::API::test2_stack->top;
79  
80 0 my $trace = $self->trace($hub);
81  
82 0 $hub->send(
83 Test2::Event::Exception->new(
84 trace => $trace,
85 error => $err,
86 ),
87 );
88 }
89  
90 663 ▶sub filter {
Subroutine filter: called CC=23 SCAR=41.4
Pod undocumented
91 663 my $self = shift;
92 663 my ($filter) = @_;
93  
94 663 ▶ return unless $filter;
Branch: 1 branch
BranchTrueFalseTotal
unless $filter 0 663 663
95 663 ▶ return if $self->{+IS_ROOT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_root"} 0 663 663
96 663 ▶ return if $self->{+SCAFFOLD};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"scaffold"} 62 601 663
97  
98 601 ▶ if (my $name = $filter->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $filter->{"name"}) 398 203 601
99 398 my $ok = 0;
100 398 ▶ unless(ref($name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $name) 398 0 398
101 398 ▶ $ok ||= $self->{+NAME} eq $name;
Condition66%2/3
$ok ||= $self->{"name"} eq $name
l!l&&r!l&&!r
047351
MC/DC50%1/2
$ok ||= $self->{"name"} eq $name
$ok $self->{"name"} eq $name
Truth table66%2/3
A ||= B
A= $okB= $self->{"name"} eq $name
ABresult
1X1
011
000
102 398 ▶ $ok ||= $self->subname eq $name;
Condition66%2/3
$ok ||= $self->subname eq $name
l!l&&r!l&&!r
470351
MC/DC50%1/2
$ok ||= $self->subname eq $name
$ok $self->subname eq $name
Truth table66%2/3
A ||= B
A= $okB= $self->subname eq $name
ABresult
1X1
011
000
103 }
104 398 ▶ if (ref($name) eq 'Regexp') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $name eq 'Regexp') { } 0 398 398
elsif ($name =~ m[^/]) { } 0 398 398
105 0 ▶ $ok ||= $self->{+NAME} =~ $name;
Condition0%0/3
$ok ||= $self->{"name"} =~ /$name/
l!l&&r!l&&!r
000
MC/DC0%0/2
$ok ||= $self->{"name"} =~ /$name/
$ok $self->{"name"} =~ /$name/
Truth table0%0/3
A ||= B
A= $okB= $self->{"name"} =~ /$name/
ABresult
1X1
011
000
106 0 ▶ $ok ||= $self->subname =~ $name;
Condition0%0/3
$ok ||= $self->subname =~ /$name/
l!l&&r!l&&!r
000
MC/DC0%0/2
$ok ||= $self->subname =~ /$name/
$ok $self->subname =~ /$name/
Truth table0%0/3
A ||= B
A= $okB= $self->subname =~ /$name/
ABresult
1X1
011
000
107 }
108 elsif ($name =~ m{^/}) {
109 0 ▶ my $pattern = eval "qr$name" or die "'$name' does not appear to be a valid pattern";
Branch: 1 branch
BranchTrueFalseTotal
my $pattern = eval "qr$name" or die "'${name}' does not appear to be a valid pattern" 0 0 0
110 0 ▶ $ok ||= $self->{+NAME} =~ $pattern;
Condition0%0/3
$ok ||= $self->{"name"} =~ /$pattern/
l!l&&r!l&&!r
000
MC/DC0%0/2
$ok ||= $self->{"name"} =~ /$pattern/
$ok $self->{"name"} =~ /$pattern/
Truth table0%0/3
A ||= B
A= $okB= $self->{"name"} =~ /$pattern/
ABresult
1X1
011
000
111 0 ▶ $ok ||= $self->subname =~ $pattern;
Condition0%0/3
$ok ||= $self->subname =~ /$pattern/
l!l&&r!l&&!r
000
MC/DC0%0/2
$ok ||= $self->subname =~ /$pattern/
$ok $self->subname =~ /$pattern/
Truth table0%0/3
A ||= B
A= $okB= $self->subname =~ /$pattern/
ABresult
1X1
011
000
112 }
113  
114 398 ▶ return {skip => "Does not match name filter '$name'"}
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 351 47 398
115 unless $ok;
116 }
117  
118 250 ▶ if (my $file = $filter->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $filter->{"file"}) 0 250 250
119 0 ▶ return {skip => "Does not match file filter '$file'"}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->file eq $file 0 0 0
120 unless $self->file eq $file;
121 }
122  
123 250 ▶ if (my $line = $filter->{line}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $filter->{"line"}) 203 47 250
124 203 my $lines = $self->lines;
125  
126 203 ▶ return {skip => "Does not match line filter '$line' (no lines)"}
Branch: 1 branch
BranchTrueFalseTotal
unless $lines and @$lines 0 203 203
Condition33%1/3
$lines and @$lines
!ll&&!rl&&r
00203
MC/DC0%0/2
$lines and @$lines
$lines @$lines
Truth table33%1/3
A and B
A= $linesB= @$lines
ABresult
0X0
100
111
127 unless $lines && @$lines;
128  
129 203 my $min = min(@$lines);
130 203 my $max = max(@$lines);
131  
132 203 ▶ return {skip => "Does not match line filter '$min <= $line <= $max'"}
Branch: 1 branch
BranchTrueFalseTotal
unless $min <= $line and $max >= $line 172 31 203
Condition100%3/3
$min <= $line and $max >= $line
!ll&&!rl&&r
789431
MC/DC100%2/2
$min <= $line and $max >= $line
$min <= $line $max >= $line
Truth table100%3/3
A and B
A= $min <= $lineB= $max >= $line
ABresult
0X0
100
111
133 unless $min <= $line && $max >= $line;
134 }
135  
136 78 return;
137 }
138  
139 40 1;
140  
141 __END__
« blib/lib/Test2/IPC.pm ↑ Summary blib/lib/Test2/Workflow/Runner.pm »