blib/lib/Test2/Workflow/Build.pm

filter: Statementstmt 100% 69 / 69 Branchbran 92.8% 13 / 14 Conditioncond 64.2% 9 / 14 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 3 totaltotal 88.2% 105 / 119 CC 17 SCAR 18.9
CC
17
Cov
94%
compile
12.1
init
4.1
populated
3.0
CRAP 6.6
« blib/lib/Test2/Util/Facets2Legacy.pm ↑ Summary blib/lib/Test2/Handle.pm »
1 package Test2::Workflow::Build;
2 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 37 our $VERSION = '1.302226';
6  
7 37 ▶use Test2::Workflow::Task::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 37 our @BUILD_FIELDS;
10  
11 37 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 37 @BUILD_FIELDS = qw{
13 primary variant
14 setup teardown
15 variant_setup variant_teardown
16 primary_setup primary_teardown
17 stash
18 };
19 }
20  
21 37 ▶use base 'Test2::Workflow::Task';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 37 ▶use Test2::Util::HashBase @BUILD_FIELDS, qw/events defaults stack_stop/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 78 ▶sub init {
Subroutine init: called CC=4 SCAR=14.2
Pod undocumented
25 78 my $self = shift;
26  
27 {
28 78 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
29 78 $self->SUPER::init();
30 }
31  
32 78 ▶ $self->{$_} ||= [] for @BUILD_FIELDS;
Condition50%1/2
$self->{$_} ||= []
l!l
0702
MC/DC0%0/1
$self->{$_} ||= []
$self->{$_}
Truth table50%1/2
A
A= $self->{$_}
Aresult
11
00
33 78 ▶ $self->{+DEFAULTS} ||= {};
Condition50%1/2
$self->{"defaults"} ||= {}
l!l
078
MC/DC0%0/1
$self->{"defaults"} ||= {}
$self->{"defaults"}
Truth table50%1/2
A
A= $self->{"defaults"}
Aresult
11
00
34 }
35  
36 37 for my $field (@BUILD_FIELDS) {
37 496 ▶ my $code = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 496 my $self = shift;
39 496 push @{$self->{$field}} => @_;
40 333 };
41 37 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 333 *{"add_$field"} = $code;
43 }
44  
45 101 ▶sub populated {
Subroutine populated: called CC=3 SCAR=11.0
Pod undocumented
46 101 my $self = shift;
47 101 for my $field (@BUILD_FIELDS) {
48 117 ▶ return 1 if @{$self->{$field}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{$field};} 99 18 117
49 }
50 2 return 0;
51 }
52  
53 67 ▶sub compile {
Subroutine compile: called CC=12 SCAR=24.9
Pod undocumented
54 67 my $self = shift;
55  
56 warn "Workflow build '$self->{+NAME}' is empty " . $self->debug . "\n"
57 67 ▶ unless $self->populated || $self->{+SKIP};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->populated or $self->{"skip"} 0 67 67
Condition33%1/3
$self->populated or $self->{"skip"}
l!l&&r!l&&!r
6700
MC/DC0%0/2
$self->populated or $self->{"skip"}
$self->populated $self->{"skip"}
Truth table33%1/3
A or B
A= $self->populatedB= $self->{"skip"}
ABresult
1X1
011
000
58  
59 67 my ($primary_setup, $primary_teardown) = @_;
60 67 ▶ $primary_setup ||= [];
Condition100%2/2
$primary_setup ||= []
l!l
2641
MC/DC100%1/1
$primary_setup ||= []
$primary_setup
Truth table100%2/2
A
A= $primary_setup
Aresult
11
00
61 67 ▶ $primary_teardown ||= [];
Condition100%2/2
$primary_teardown ||= []
l!l
2641
MC/DC100%1/1
$primary_teardown ||= []
$primary_teardown
Truth table100%2/2
A
A= $primary_teardown
Aresult
11
00
62  
63 67 my $variant = $self->{+VARIANT};
64 67 my $setup = $self->{+SETUP};
65 67 my $teardown = $self->{+TEARDOWN};
66 67 my $variant_setup = $self->{+VARIANT_SETUP};
67 67 my $variant_teardown = $self->{+VARIANT_TEARDOWN};
68  
69 67 $primary_setup = [@$primary_setup, @{$self->{+PRIMARY_SETUP}}];
70 67 $primary_teardown = [@{$self->{+PRIMARY_TEARDOWN}}, @$primary_teardown];
71  
72 # Get primaries in order.
73 my $primary = [
74 map {
75 276 ▶ $_->isa(__PACKAGE__)
Branch: 1 branch
BranchTrueFalseTotal
$_->isa(__PACKAGE__) ? : 26 250 276
76 ? $_->compile($primary_setup, $primary_teardown)
77 : $_;
78 67 } @{$self->{+PRIMARY}},
79 ];
80  
81 67 ▶ if (@$primary_setup || @$primary_teardown) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$primary_setup or @$primary_teardown) 20 47 67
Condition66%2/3
@$primary_setup or @$primary_teardown
l!l&&r!l&&!r
20047
MC/DC50%1/2
@$primary_setup or @$primary_teardown
@$primary_setup @$primary_teardown
Truth table66%2/3
A or B
A= @$primary_setupB= @$primary_teardown
ABresult
1X1
011
000
82 $primary = [
83 map {
84 20 my $p = $_->clone;
85 84 ▶ $_->isa('Test2::Workflow::Task::Action') ? Test2::Workflow::Task::Group->new(
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('Test2::Workflow::Task::Action') ? : 74 10 84
86 before => $primary_setup,
87 primary => [ $p ],
88 take => $p,
89 after => $primary_teardown,
90 ) : $_;
91 } @$primary
92 ];
93 }
94  
95 # Build variants
96 67 ▶ if (@$variant) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$variant) 30 37 67
97 $primary = [
98 map {
99 30 my $v = $_->clone;
100 60 Test2::Workflow::Task::Group->new(
101 before => $variant_setup,
102 primary => $primary,
103 after => $variant_teardown,
104 variant => $v,
105 take => $v,
106 );
107 } @$variant
108 ];
109 }
110  
111 67 ▶ my %params = map { Test2::Workflow::Task::Group->can($_) ? ($_ => $self->{$_}) : () } keys %$self;
Branch: 1 branch
BranchTrueFalseTotal
'Test2::Workflow::Task::Group'->can($_) ? : 539 571 1110
112 67 delete $params{$_} for @BUILD_FIELDS;
113  
114 67 return Test2::Workflow::Task::Group->new(
115 %params,
116 before => $setup,
117 after => $teardown,
118 primary => $primary,
119 );
120 }
121  
122 37 1;
123  
124 __END__
« blib/lib/Test2/Util/Facets2Legacy.pm ↑ Summary blib/lib/Test2/Handle.pm »