lib/Daje/Workflow/Activities.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 77 CC 11 SCAR 45.1
CC
11
Cov
0%
activity
132.0
_observers
2.0
_post_checks
2.0
CRAP 91.4
1 package Daje::Workflow::Activities;
2 use Mojo::Base -base, -signatures;
3  
4 use Mojo::Loader qw(load_class);
5  
6 # Daje::Workflow::Activities::Activity - Manage activities in the workflow
7 #
8 #
9 # METHODS
10 # =======
11 #
12 # action($self, $context, $activity);
13 #
14 # $activity = {
15 # "name": "sql",
16 # "activity": "Daje::Plugin::GenerateSQL",
17 # "method": "genereate",
18 # "resulting_state": "",
19 # "pre_checks": [],
20 # "post_checks":[],
21 # "observers": [],
22 # "activity_data": {
23 # "Activity specific content"
24 # }
25 # }
26 #
27 #
28 #
29  
30 has 'db';
31 has 'error';
32 has 'history';
33 has 'model';
34  
35 sub activity($self, $context, $activity, $workflow_data) {
36 return 1 unless defined $activity;
37  
38 my $result = 1;
39 if ($self->_pre_checks($activity->{pre_checks}
40 and $self->error->has_error() == 0)) {
41 if (my $e = load_class $activity->{activity}) {
42 $self->error->add_error($e);
43 $self->error->add_error($activity->{activity} . " Not found $e");
44 }
45 return 0 if $self->error->has_error();
46  
47 my $activity_data;
48 $activity_data = $activity->{activity_data}
49 if exists $activity->{activity_data};
50  
51 $self->model->insert_history($activity->{method}, $activity->{activity}, 1);
52 my $object = $activity->{activity}->new(
53 context => $context,
54 db => $self->db,
55 error => $self->error,
56 model => $self->model,
57 activity_data => $activity_data,
58 );
59  
60 my $method = $activity->{method};
61 if ($object->can($method)) {
62 eval {
63 $object->$method
64 };
65 $self->error->add_error($@) if defined $@;
66 }
67 else {
68 $self->error->add_error(
69 $activity->{activity} .
70 " does not have a method called '" .
71 $activity->{method} . "'"
72 );
73 }
74 if ($self->error->has_error() == 0) {
75 if ($self->_post_checks($activity->{post_checks}
76 and $self->error->has_error() == 0) ) {
77 $self->_observers($activity->{post_checks} );
78 }
79 }
80 if ($self->error->has_error() == 0) {
81 $workflow_data->{next_state} = $activity->{resulting_state};
82 }
83 }
84  
85 return 1;
86 }
87  
88 sub _observers($self, $observers) {
89  
90 return 1;
91 }
92  
93 sub _post_checks($self, $post_checks) {
94  
95 return 1;
96 }
97  
98 sub _pre_checks($self, $pre_checks) {
99  
100 return 1;
101 }
102  
103 1;
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116 #################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################
117  
118 =head1 NAME
119  
120 Daje::Workflow::Activities
121  
122  
123 =head1 DESCRIPTION
124  
125 Daje::Workflow::Activities::Activity - Manage activities in the workflow
126  
127  
128  
129  
130 =head1 REQUIRES
131  
132 L<Mojo::Loader>
133  
134 L<Mojo::Base>
135  
136  
137 =head1 METHODS
138  
139  
140 action($self, $context, $activity);
141  
142 $activity = {
143 "name": "sql",
144 "activity": "Daje::Plugin::GenerateSQL",
145 "method": "genereate",
146 "resulting_state": "",
147 "pre_checks": [],
148 "post_checks":[],
149 "observers": [],
150 "activity_data": {
151 "Activity specific content"
152 }
153 }
154  
155  
156  
157  
158  
159 =cut
160