line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Workflow; |
2
|
45
|
|
|
45
|
|
318
|
use strict; |
|
45
|
|
|
|
|
104
|
|
|
45
|
|
|
|
|
1254
|
|
3
|
45
|
|
|
45
|
|
311
|
use warnings; |
|
45
|
|
|
|
|
74
|
|
|
45
|
|
|
|
|
2331
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000153'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/parse_args current_build build root_build init_root build_stack/; |
8
|
45
|
|
|
45
|
|
260
|
use base 'Exporter'; |
|
45
|
|
|
|
|
83
|
|
|
45
|
|
|
|
|
4070
|
|
9
|
|
|
|
|
|
|
|
10
|
45
|
|
|
45
|
|
17772
|
use Test2::Workflow::Build; |
|
45
|
|
|
|
|
123
|
|
|
45
|
|
|
|
|
1252
|
|
11
|
45
|
|
|
45
|
|
276
|
use Test2::Workflow::Task::Group; |
|
45
|
|
|
|
|
94
|
|
|
45
|
|
|
|
|
914
|
|
12
|
45
|
|
|
45
|
|
240
|
use Test2::API qw/intercept/; |
|
45
|
|
|
|
|
94
|
|
|
45
|
|
|
|
|
2520
|
|
13
|
45
|
|
|
45
|
|
365
|
use Scalar::Util qw/blessed/; |
|
45
|
|
|
|
|
112
|
|
|
45
|
|
|
|
|
41260
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub parse_args { |
16
|
739
|
|
|
739
|
1
|
2267
|
my %input = @_; |
17
|
739
|
|
|
|
|
1550
|
my $args = delete $input{args}; |
18
|
739
|
|
|
|
|
1354
|
my %out; |
19
|
|
|
|
|
|
|
my %props; |
20
|
|
|
|
|
|
|
|
21
|
739
|
|
33
|
|
|
2259
|
my $caller = $out{frame} = $input{caller} || caller(defined $input{level} ? $input{level} : 1); |
22
|
739
|
|
|
|
|
1668
|
delete @input{qw/caller level/}; |
23
|
|
|
|
|
|
|
|
24
|
739
|
|
|
|
|
1488
|
for my $arg (@$args) { |
25
|
1702
|
100
|
|
|
|
3910
|
if (my $r = ref($arg)) { |
26
|
963
|
100
|
|
|
|
2482
|
if ($r eq 'HASH') { |
|
|
50
|
|
|
|
|
|
27
|
224
|
|
|
|
|
875
|
%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
|
739
|
50
|
|
|
|
1617
|
if $out{code}; |
32
|
|
|
|
|
|
|
|
33
|
739
|
|
|
|
|
1222
|
$out{code} = $arg |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
0
|
die "Not sure what to do with $arg at $caller->[1] line $caller->[2].\n"; |
37
|
|
|
|
|
|
|
} |
38
|
963
|
|
|
|
|
1940
|
next; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
739
|
50
|
|
|
|
2737
|
if ($arg =~ m/^\d+$/) { |
42
|
0
|
|
|
|
|
0
|
push @{$out{lines}} => $arg; |
|
0
|
|
|
|
|
0
|
|
43
|
0
|
|
|
|
|
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
|
739
|
50
|
|
|
|
1574
|
if $out{name}; |
48
|
|
|
|
|
|
|
|
49
|
739
|
|
|
|
|
1684
|
$out{name} = $arg; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
die "a name must be provided, and must be truthy at $caller->[1] line $caller->[2].\n" |
53
|
739
|
50
|
|
|
|
1569
|
unless $out{name}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
die "a codeblock must be provided at $caller->[1] line $caller->[2].\n" |
56
|
739
|
50
|
|
|
|
1603
|
unless $out{code}; |
57
|
|
|
|
|
|
|
|
58
|
739
|
|
|
|
|
4733
|
return { %props, %out, %input }; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
my %ROOT_BUILDS; |
63
|
|
|
|
|
|
|
my @BUILD_STACK; |
64
|
|
|
|
|
|
|
|
65
|
841
|
|
|
841
|
1
|
2596
|
sub root_build { $ROOT_BUILDS{$_[0]} } |
66
|
730
|
100
|
|
730
|
1
|
4021
|
sub current_build { @BUILD_STACK ? $BUILD_STACK[-1] : undef } |
67
|
646
|
|
|
646
|
0
|
1330
|
sub build_stack { @BUILD_STACK } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub init_root { |
70
|
43
|
|
|
43
|
1
|
211
|
my ($pkg, %args) = @_; |
71
|
43
|
|
33
|
|
|
665
|
$ROOT_BUILDS{$pkg} ||= Test2::Workflow::Build->new( |
72
|
|
|
|
|
|
|
name => $pkg, |
73
|
|
|
|
|
|
|
flat => 1, |
74
|
|
|
|
|
|
|
iso => 0, |
75
|
|
|
|
|
|
|
async => 0, |
76
|
|
|
|
|
|
|
is_root => 1, |
77
|
|
|
|
|
|
|
%args, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
43
|
|
|
|
|
325
|
return $ROOT_BUILDS{$pkg}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub build { |
84
|
92
|
|
|
92
|
1
|
559
|
my %params = @_; |
85
|
92
|
|
|
|
|
363
|
my $args = parse_args(%params); |
86
|
|
|
|
|
|
|
|
87
|
92
|
|
|
|
|
876
|
my $build = Test2::Workflow::Build->new(%$args); |
88
|
|
|
|
|
|
|
|
89
|
92
|
100
|
|
|
|
606
|
return $build if $args->{skip}; |
90
|
|
|
|
|
|
|
|
91
|
87
|
|
|
|
|
194
|
push @BUILD_STACK => $build; |
92
|
|
|
|
|
|
|
|
93
|
87
|
|
|
|
|
213
|
my ($ok, $err); |
94
|
|
|
|
|
|
|
my $events = intercept { |
95
|
87
|
100
|
|
87
|
|
97877
|
my $todo = $args->{todo} ? Test2::Todo->new(reason => $args->{todo}) : undef; |
96
|
87
|
|
|
|
|
271
|
$ok = eval { $args->{code}->(); 1 }; |
|
87
|
|
|
|
|
309
|
|
|
82
|
|
|
|
|
316
|
|
97
|
87
|
|
|
|
|
279
|
$err = $@; |
98
|
87
|
100
|
|
|
|
372
|
$todo->end if $todo; |
99
|
87
|
|
|
|
|
909
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Clear the stash |
102
|
87
|
|
|
|
|
318351
|
$build->{stash} = []; |
103
|
87
|
|
|
|
|
457
|
$build->set_events($events); |
104
|
|
|
|
|
|
|
|
105
|
87
|
|
|
|
|
410
|
pop @BUILD_STACK; |
106
|
|
|
|
|
|
|
|
107
|
87
|
100
|
|
|
|
287
|
unless($ok) { |
108
|
5
|
|
|
|
|
25
|
my $hub = Test2::API::test2_stack->top; |
109
|
5
|
|
|
|
|
70
|
my $count = @$events; |
110
|
5
|
50
|
|
|
|
60
|
my $list = $count |
111
|
|
|
|
|
|
|
? "Overview of unseen events:\n" . join "" => map " " . blessed($_) . " " . $_->trace($hub)->debug . "\n", @$events |
112
|
|
|
|
|
|
|
: ""; |
113
|
5
|
|
|
|
|
480
|
die <<" EOT"; |
114
|
|
|
|
|
|
|
Exception in build '$args->{name}' with $count unseen event(s). |
115
|
|
|
|
|
|
|
$err |
116
|
|
|
|
|
|
|
$list |
117
|
|
|
|
|
|
|
EOT |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
82
|
|
|
|
|
388
|
return $build; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |