line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Action::Step; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
83139
|
use warnings; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
439
|
|
4
|
6
|
|
|
6
|
|
34
|
use strict; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
687
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$Class::Action::Step::VERSION = '0.4'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# get a collection of step objects: |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub get_class_action_steps { |
11
|
0
|
|
|
0
|
1
|
0
|
my ( $class, @args ) = @_; |
12
|
0
|
|
|
|
|
0
|
return $class->_not_imp('get_class_action_steps'); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# basic functionality convienience shortcut: |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# turn X=>sub {}, Y=>sub {} into CALLER::NS::X::execute() && CALLER::NS::Y::execute() |
18
|
|
|
|
|
|
|
# return list sutiable for get_class_action_steps() return value |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub setup_class_execute_and_get_class_action_steps { |
21
|
1
|
|
|
1
|
1
|
20
|
my $class = shift; |
22
|
1
|
50
|
|
|
|
5
|
$class = ref($class) if ref($class); |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
6
|
|
35
|
no strict 'refs'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
8882
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
my @nss; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# no warnings 'redefine'; # we want to warn since it doesn't make |
29
|
|
|
|
|
|
|
# much sense to pass an NS that already has execute() to this method |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $ar; # re-use buffer, cheaper on memory |
32
|
1
|
|
|
|
|
2
|
for $ar (@_) { |
33
|
4
|
50
|
|
|
|
20
|
if ( $ar->[0] !~ m/\A[A-Za-z_][A-Za-z_0-9]*\z/ ) { |
34
|
0
|
|
|
|
|
0
|
require Carp; |
35
|
0
|
|
|
|
|
0
|
Carp::carp('Invalid string for use in a namespace'); |
36
|
0
|
|
|
|
|
0
|
@nss = (); |
37
|
0
|
|
|
|
|
0
|
last; |
38
|
|
|
|
|
|
|
} |
39
|
4
|
50
|
|
|
|
13
|
if ( ref( $ar->[1] ) ne 'CODE' ) { |
40
|
0
|
|
|
|
|
0
|
require Carp; |
41
|
0
|
|
|
|
|
0
|
Carp::carp('Not a CODE reference'); |
42
|
0
|
|
|
|
|
0
|
@nss = (); |
43
|
0
|
|
|
|
|
0
|
last; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
5
|
push @{ $class . "::$ar->[0]" . '::ISA' }, $class; |
|
4
|
|
|
|
|
61
|
|
47
|
4
|
|
|
|
|
6
|
*{ $class . "::$ar->[0]" . '::execute' } = $ar->[1]; |
|
4
|
|
|
|
|
20
|
|
48
|
|
|
|
|
|
|
|
49
|
4
|
100
|
|
|
|
12
|
if ( ref($ar->[2]) eq 'CODE' ) { |
50
|
1
|
|
|
|
|
3
|
*{ $class . "::$ar->[0]" . '::undo' } = $ar->[2]; |
|
1
|
|
|
|
|
5
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
12
|
push @nss, $class . "::$ar->[0]"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
12
|
return @nss; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# basic functionality convienience shortcut: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_action_object { |
62
|
1
|
|
|
1
|
1
|
1070
|
require Class::Action; |
63
|
1
|
|
|
|
|
8
|
my $action = Class::Action->new(); |
64
|
1
|
|
|
|
|
5
|
$action->set_steps_from_class(@_); |
65
|
1
|
|
|
|
|
4
|
return $action; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#### mandatory step object methods ## |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
0
|
|
|
0
|
1
|
0
|
my ($step_obj) = @_; |
72
|
0
|
|
|
|
|
0
|
return $step_obj->_not_imp('new'); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# my ($step_obj, @args_to_execute) = @_; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub clone_obj { |
78
|
0
|
|
|
0
|
1
|
0
|
my ($step_obj) = @_; |
79
|
0
|
|
|
|
|
0
|
return $step_obj->_not_imp('clone_obj'); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# return a cloned $step_obj |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub state { |
85
|
0
|
|
|
0
|
1
|
0
|
my ($step_obj) = @_; |
86
|
0
|
|
|
|
|
0
|
return $step_obj->_not_imp('state'); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# return string/data struct representing any important messages and status that you might want to examine after reset_obj_state() has wiped the object clean |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub reset_obj_state { |
92
|
0
|
|
|
0
|
1
|
0
|
my ($step_obj) = @_; |
93
|
0
|
|
|
|
|
0
|
return $step_obj->_not_imp('reset_obj_state'); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# my ($step_obj) = @_; |
96
|
|
|
|
|
|
|
# resets the intrnal state of the obj |
97
|
|
|
|
|
|
|
# void context |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub execute { |
101
|
0
|
|
|
0
|
1
|
0
|
my ($step_obj) = @_; |
102
|
0
|
|
|
|
|
0
|
$step_obj->_not_imp('execute'); |
103
|
0
|
|
|
|
|
0
|
return 1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# my ($step_obj, $global_data_hr, @args_to_execute) = @_; |
106
|
|
|
|
|
|
|
# return 1 if what it does worked |
107
|
|
|
|
|
|
|
# return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#### optional step object methods ## |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub retry_execute { |
113
|
0
|
|
|
0
|
1
|
0
|
return; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# my ($step_obj, $global_data_hr, @args_to_execute) = @_; |
116
|
|
|
|
|
|
|
# Address $step_obj->execute() failure as needed |
117
|
|
|
|
|
|
|
# return 1 if $retry; # i.e. we should try $step_obj->execute() again |
118
|
|
|
|
|
|
|
# return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub clean_failed_execute { |
122
|
0
|
|
|
0
|
1
|
0
|
return; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# my ($step_obj, $global_data_hr, @args_to_execute) = @_; |
125
|
|
|
|
|
|
|
# final $step_obj->execute() cleanup since the $step_obj->execute() failed and we are not retrying |
126
|
|
|
|
|
|
|
# void context |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# same idea as the execute equivalents (sans that undo() is optional) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub undo { |
132
|
4
|
|
|
4
|
1
|
10
|
return 1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# my ($step_obj, $global_data_hr, @args_to_execute) = @_; |
135
|
|
|
|
|
|
|
# return 1 if what it does worked |
136
|
|
|
|
|
|
|
# return; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub retry_undo { |
140
|
0
|
|
|
0
|
1
|
0
|
return; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# my ($step_obj, $global_data_hr, @args_to_execute) = @_; |
143
|
|
|
|
|
|
|
# Address $step_obj->undo() failure as needed |
144
|
|
|
|
|
|
|
# return 1 if $retry; # i.e. we should try $step_obj->undo() again |
145
|
|
|
|
|
|
|
# return; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub clean_failed_undo { |
149
|
0
|
|
|
0
|
1
|
0
|
return; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# my ($step_obj, $global_data_hr, @args_to_execute) = @_; |
152
|
|
|
|
|
|
|
# final $step_obj->undo() cleanup since the $step_obj->undo() failed and we are not retrying |
153
|
|
|
|
|
|
|
# void context |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub exec_stack_runtime_handler { |
157
|
67
|
|
|
67
|
1
|
188
|
return; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# my ($step_obj, $current_exec_stack_entry_hr) = @_; |
160
|
|
|
|
|
|
|
# void context |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
#### Internal ## |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _not_imp { |
166
|
0
|
|
|
0
|
|
|
my ( $step_obj, $method ) = @_; |
167
|
0
|
|
|
|
|
|
require Carp; |
168
|
0
|
|
|
|
|
|
local $Carp::CarpLevel = $Carp::CarpLevel + 1; |
169
|
0
|
|
0
|
|
|
|
Carp::carp( ( ref($step_obj) || $step_obj ) . " does not implement $method()" ); |
170
|
0
|
|
|
|
|
|
return; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |