blib/lib/Test2/Workflow.pm

filter: Statementstmt 89.6% 69 / 77 Branchbran 53.3% 16 / 30 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 14 / 14 Podpod 83.3% 5 / 6 totaltotal 77.3% 106 / 137 CC 19 SCAR 20.5
CC
19
Cov
77%
parse_args
17.0
build
4.5
__ANON__
3.1
CRAP 7.8
« blib/lib/Test2/Util/HashBase.pm ↑ Summary blib/lib/Test2/Workflow/Task/Group.pm »
1 package Test2::Workflow;
2 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 36 our $VERSION = '1.302226';
6  
7 36 our @EXPORT_OK = qw/parse_args current_build build root_build init_root build_stack/;
8 36 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 36 ▶use Test2::Workflow::Build;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 36 ▶use Test2::Workflow::Task::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 36 ▶use Test2::API qw/intercept/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 36 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 476 ▶sub parse_args {
Subroutine parse_args: called CC=12 SCAR=28.3
Pod documented
16 476 my %input = @_;
17 476 my $args = delete $input{args};
18 476 my %out;
19 my %props;
20  
21 476 ▶ my $caller = $out{frame} = $input{caller} || caller(defined $input{level} ? $input{level} : 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $input{'level'} ? : 0 0 0
Condition33%1/3
$input{'caller'} || caller(defined $input{'level'} ? $input{'level'} : 1)
l!l&&r!l&&!r
47600
MC/DC0%0/2
$input{'caller'} || caller(defined $input{'level'} ? $input{'level'} : 1)
$input{'caller'} caller(defined $input{'level'} ? $input{'level'} : 1)
Truth table33%1/3
A || B
A= $input{'caller'}B= caller(defined $input{'level'} ? $input{'level'} : 1)
ABresult
1X1
011
000
22 476 delete @input{qw/caller level/};
23  
24 476 for my $arg (@$args) {
25 1105 ▶ if (my $r = ref($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = ref $arg) 629 476 1105
26 629 ▶ if ($r eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($r eq 'HASH') { } 153 476 629
elsif ($r eq 'CODE') { } 476 0 476
27 153 %props = (%props, %$arg);
28 }
29 elsif ($r eq 'CODE') {
30 die "Code is already set, did you provide multiple code blocks at $caller->[1] line $caller->[2].\n"
31 476 ▶ if $out{code};
Branch: 1 branch
BranchTrueFalseTotal
if $out{"code"} 0 476 476
32  
33 476 $out{code} = $arg
34 }
35 else {
36 0 die "Not sure what to do with $arg at $caller->[1] line $caller->[2].\n";
37 }
38 629 next;
39 }
40  
41 476 ▶ if ($arg =~ m/^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^\d+$/) 0 476 476
42 0 push @{$out{lines}} => $arg;
43 0 next;
44 }
45  
46 die "Name is already set to '$out{name}', cannot set to '$arg', did you specify multiple names at $caller->[1] line $caller->[2].\n"
47 476 ▶ if $out{name};
Branch: 1 branch
BranchTrueFalseTotal
if $out{"name"} 0 476 476
48  
49 476 $out{name} = $arg;
50 }
51  
52 die "a name must be provided, and must be truthy at $caller->[1] line $caller->[2].\n"
53 476 ▶ unless $out{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $out{"name"} 0 476 476
54  
55 die "a codeblock must be provided at $caller->[1] line $caller->[2].\n"
56 476 ▶ unless $out{code};
Branch: 1 branch
BranchTrueFalseTotal
unless $out{"code"} 0 476 476
57  
58 476 return { %props, %out, %input };
59 }
60  
61 {
62 36 my %ROOT_BUILDS;
63 36 my @BUILD_STACK;
64  
65 606 ▶ sub root_build { $ROOT_BUILDS{$_[0]} }
Subroutine root_build: called CC=1 SCAR=0.0
Pod documented
66 476 ▶ sub current_build { @BUILD_STACK ? $BUILD_STACK[-1] : undef }
Subroutine current_build: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@BUILD_STACK ? : 301 175 476
67 431 ▶ sub build_stack { @BUILD_STACK }
Subroutine build_stack: called CC=1 SCAR=0.0
Pod undocumented
68  
69 34 ▶ sub init_root {
Subroutine init_root: called CC=2 SCAR=7.6
Pod documented
70 34 my ($pkg, %args) = @_;
71 34 ▶ $ROOT_BUILDS{$pkg} ||= Test2::Workflow::Build->new(
Condition33%1/3
$ROOT_BUILDS{$pkg} ||= "Test2::Workflow::Build"->new("name", $pkg, "flat", 1, "iso", 0, "async", 0, "is_root", 1, %args)
l!l&&r!l&&!r
0340
MC/DC0%0/2
$ROOT_BUILDS{$pkg} ||= "Test2::Workflow::Build"->new("name", $pkg, "flat", 1, "iso", 0, "async", 0, "is_root", 1, %args)
$ROOT_BUILDS{$pkg} "Test2::Workflow::Build"->new("name", $pkg, "flat", 1, "iso", 0, "async", 0, "is_root", 1, %args)
Truth table33%1/3
A ||= B
A= $ROOT_BUILDS{$pkg}B= "Test2::Workflow::Build"->new("name", $pkg, "flat", 1, "iso", 0, "async", 0, "is_root", 1, %args)
ABresult
1X1
011
000
72 name => $pkg,
73 flat => 1,
74 iso => 0,
75 async => 0,
76 is_root => 1,
77 %args,
78 );
79  
80 34 return $ROOT_BUILDS{$pkg};
81 }
82  
83 44 ▶ sub build {
Subroutine build: called CC=4 SCAR=15.0
Pod documented
84 44 my %params = @_;
85 44 my $args = parse_args(%params);
86  
87 44 my $build = Test2::Workflow::Build->new(%$args);
88  
89 44 ▶ return $build if $args->{skip};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"skip"} 0 44 44
90  
91 44 push @BUILD_STACK => $build;
92  
93 44 my ($ok, $err);
94 44 ▶ my $events = intercept {
Subroutine __ANON__: called CC=3 SCAR=11.2
95 44 ▶ my $todo = $args->{todo} ? Test2::Todo->new(reason => $args->{todo}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args->{'todo'} ? : 0 44 44
96 44 $ok = eval { $args->{code}->(); 1 };
97 44 $err = $@;
98 44 ▶ $todo->end if $todo;
Branch: 1 branch
BranchTrueFalseTotal
if $todo 0 44 44
99 44 };
100  
101 # Clear the stash
102 44 $build->{stash} = [];
103 44 $build->set_events($events);
104  
105 44 pop @BUILD_STACK;
106  
107 44 ▶ unless($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 44 44
108 0 my $hub = Test2::API::test2_stack->top;
109 0 my $count = @$events;
110 0 ▶ my $list = $count
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 0 0 0
111 ? "Overview of unseen events:\n" . join "" => map " " . blessed($_) . " " . $_->trace($hub)->debug . "\n", @$events
112 : "";
113 0 die <<" EOT";
114 Exception in build '$args->{name}' with $count unseen event(s).
115 $err
116 $list
117 EOT
118 }
119  
120 44 return $build;
121 }
122 }
123  
124 36 1;
125  
126 __END__
« blib/lib/Test2/Util/HashBase.pm ↑ Summary blib/lib/Test2/Workflow/Task/Group.pm »