Action/Step.pm

filter: Statementstmt 51.6% 32 / 62 Branchbran 62.5% 5 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.8% 7 / 18 Podpod 100% 14 / 14 totaltotal 54.2% 58 / 107 CC 7 SCAR 12.2
CC
7
Cov
51%
setup_class_execute_and_get_class_action_steps
7.2
_not_imp
6.0
get_class_action_steps
2.0
CRAP 3.4
« Action.pm ↑ Summary
1 package Class::Action::Step;
2  
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 $Class::Action::Step::VERSION = '0.4';
7  
8 # get a collection of step objects:
9  
10 0 ▶sub get_class_action_steps {
Subroutine get_class_action_steps: not called CC=1 SCAR=6.9
Pod documented
11 0 my ( $class, @args ) = @_;
12 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 1 ▶sub setup_class_execute_and_get_class_action_steps {
Subroutine setup_class_execute_and_get_class_action_steps: called CC=6 SCAR=19.8
Pod documented
21 1 my $class = shift;
22 1 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
23  
24 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 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 for $ar (@_) {
33 4 ▶ if ( $ar->[0] !~ m/\A[A-Za-z_][A-Za-z_0-9]*\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ar->[0] =~ /\A[A-Za-z_][A-Za-z_0-9]*\z/) 0 4 4
34 0 require Carp;
35 0 Carp::carp('Invalid string for use in a namespace');
36 0 @nss = ();
37 0 last;
38 }
39 4 ▶ if ( ref( $ar->[1] ) ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ar->[1] ne "CODE") 0 4 4
40 0 require Carp;
41 0 Carp::carp('Not a CODE reference');
42 0 @nss = ();
43 0 last;
44 }
45  
46 4 push @{ $class . "::$ar->[0]" . '::ISA' }, $class;
47 4 *{ $class . "::$ar->[0]" . '::execute' } = $ar->[1];
48  
49 4 ▶ if ( ref($ar->[2]) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ar->[2] eq "CODE") 1 3 4
50 1 *{ $class . "::$ar->[0]" . '::undo' } = $ar->[2];
51 }
52
53 4 push @nss, $class . "::$ar->[0]";
54 }
55  
56 1 return @nss;
57 }
58  
59 # basic functionality convienience shortcut:
60  
61 1 ▶sub get_action_object {
Subroutine get_action_object: called CC=1 SCAR=0.0
Pod documented
62 1 require Class::Action;
63 1 my $action = Class::Action->new();
64 1 $action->set_steps_from_class(@_);
65 1 return $action;
66 }
67  
68 #### mandatory step object methods ##
69  
70 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
71 0 my ($step_obj) = @_;
72 0 return $step_obj->_not_imp('new');
73  
74 # my ($step_obj, @args_to_execute) = @_;
75 }
76  
77 0 ▶sub clone_obj {
Subroutine clone_obj: not called CC=1 SCAR=6.9
Pod documented
78 0 my ($step_obj) = @_;
79 0 return $step_obj->_not_imp('clone_obj');
80  
81 # return a cloned $step_obj
82 }
83  
84 0 ▶sub state {
Subroutine state: not called CC=1 SCAR=6.9
Pod documented
85 0 my ($step_obj) = @_;
86 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 0 ▶sub reset_obj_state {
Subroutine reset_obj_state: not called CC=1 SCAR=6.9
Pod documented
92 0 my ($step_obj) = @_;
93 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 0 ▶sub execute {
Subroutine execute: not called CC=1 SCAR=6.9
Pod documented
101 0 my ($step_obj) = @_;
102 0 $step_obj->_not_imp('execute');
103 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 0 ▶sub retry_execute {
Subroutine retry_execute: not called CC=1 SCAR=6.9
Pod documented
113 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 0 ▶sub clean_failed_execute {
Subroutine clean_failed_execute: not called CC=1 SCAR=6.9
Pod documented
122 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 4 ▶sub undo {
Subroutine undo: called CC=1 SCAR=0.0
Pod documented
132 4 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 0 ▶sub retry_undo {
Subroutine retry_undo: not called CC=1 SCAR=6.9
Pod documented
140 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 0 ▶sub clean_failed_undo {
Subroutine clean_failed_undo: not called CC=1 SCAR=6.9
Pod documented
149 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 67 ▶sub exec_stack_runtime_handler {
Subroutine exec_stack_runtime_handler: called CC=1 SCAR=0.0
Pod documented
157 67 return;
158  
159 # my ($step_obj, $current_exec_stack_entry_hr) = @_;
160 # void context
161 }
162  
163 #### Internal ##
164  
165 0 ▶sub _not_imp {
Subroutine _not_imp: not called CC=2 SCAR=17.9
166 0 my ( $step_obj, $method ) = @_;
167 0 require Carp;
168 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
169 0 ▶ Carp::carp( ( ref($step_obj) || $step_obj ) . " does not implement $method()" );
Condition0%0/3
ref $step_obj || $step_obj
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $step_obj || $step_obj
ref $step_obj $step_obj
Truth table0%0/3
A || B
A= ref $step_objB= $step_obj
ABresult
1X1
011
000
170 0 return;
171 }
172  
173 7 1;
« Action.pm ↑ Summary