Conveyor/Ticket/Payload.pm

filter: Statementstmt 18.4% 26 / 141 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 28.1% 9 / 32 Podpod 100% 21 / 21 totaltotal 26.4% 56 / 212 CC 30 SCAR 21.6
CC
30
Cov
17%
check
20.0
__ANON__
12.0
add_items_from_list
12.0
CRAP 8.7
« Conveyor/Charset/ViaHash.pm ↑ Summary Conveyor/Storage/DBI.pm »
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Data::Conveyor::Ticket::Payload;
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $Data::Conveyor::Ticket::Payload::VERSION = '1.103130';
8 }
9 # ABSTRACT: Stage-based conveyor-belt-like ticket handling system
10  
11 # ptags: DCTP
12 #
13 # This class houses the ticket payload objects
14 1 ▶use Error::Hierarchy::Util 'assert_defined';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::Miscellany 'flatten';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use once;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use parent qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
18 Class::Scaffold::Storable
19 Class::Scaffold::HierarchicalDirty
20 1 );
21 1 __PACKAGE__->mk_scalar_accessors(qw(version))
22 ->mk_framework_object_accessors(payload_common => 'common')
23 ->mk_framework_object_array_accessors(
24 payload_transaction => 'transactions',
25 payload_lock => 'locks',
26 );
27  
28 # Generate add_* methods for each payload item. The method can be called in
29 # various ways:
30 #
31 # 1) Without any arguments: will push a new and empty payload item into the
32 # according payload item list.
33 #
34 # 2) With an payload item data object (eg. a Registry::Person) as first
35 # argument: will push the given object into the according payload item list.
36 #
37 # 3) With any number of arguments of which the first one isn't a reference:
38 # will create a new payload item with given arguments passed to the
39 # constructor. This item is pushed into the according payload item list.
40 0 ▶sub generate_add_method {
Subroutine generate_add_method: not called CC=2 SCAR=14.8
Pod documented
41 0 my ($self, $object_type, $method, $payload_object_type, $push_method) = @_;
42  
43 # FIXME: these PTAGS aren't going to work, as the methods are only
44 # generated when the application is really running, not when ptags
45 # loads the module.
46 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 0 ▶ $::PTAGS && $::PTAGS->add_tag($method, __FILE__, __LINE__ + 1);
Branch: 1 branch
BranchTrueFalseTotal
$main::PTAGS and $main::PTAGS->add_tag($method, __FILE__, 48) 0 0 0
48 0 ▶ *$method = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
49 0 my $self = shift;
50 0 my $payload_object = $self->delegate->make_obj($payload_object_type);
51  
52 # If at least one argument is given, check if it's a reference. If
53 # it is, use it as our object to set, Otherwise create a new
54 # payload item supplying all the arguments we might have gotten.
55 0 ▶ my $object =
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && ref $_[0] ? : 0 0 0
Condition0%0/3
defined $_[0] and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and ref $_[0]
defined $_[0] ref $_[0]
Truth table0%0/3
A and B
A= defined $_[0]B= ref $_[0]
ABresult
0X0
100
111
56 defined $_[0] && ref $_[0]
57 ? $_[0]
58 : $self->delegate->make_obj($object_type, @_);
59 0 $payload_object->$object_type($object);
60 0 $self->$push_method($payload_object);
61 0 return $payload_object;
62 }
63 0 }
64  
65 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
66 0 my $self = shift;
67 0 $self->SUPER::init(@_);
68 0 ▶ ONCE {
Subroutine __ANON__: not called CC=2 SCAR=17.9
69 0 for my $object_type ($self->delegate->OT) {
70 0 my $add_method = sprintf("add_%s", $object_type);
71 0 my $add_unique_method = sprintf("add_unique_%s", $object_type);
72 0 my $payload_object_type = sprintf("payload_%s", $object_type);
73 0 my $push_method = sprintf("%ss_push", $object_type);
74 0 my $set_push_method = sprintf("%ss_set_push", $object_type);
75 0 $self->generate_add_method(
76 $object_type, $add_method,
77 $payload_object_type, $push_method
78 );
79 0 $self->generate_add_method(
80 $object_type, $add_unique_method,
81 $payload_object_type, $set_push_method
82 );
83 }
84 0 };
85 }
86  
87 0 ▶sub LIST_ACCESSOR_FOR_OBJECT_TYPE {
Subroutine LIST_ACCESSOR_FOR_OBJECT_TYPE: not called CC=1 SCAR=6.9
Pod documented
88 0 local $_ = $_[0]->delegate;
89 0 ( $_->OT_LOCK => 'locks',
90 $_->OT_TRANSACTION => 'transactions',
91 );
92 }
93  
94 0 ▶sub get_list_name_for_object_type {
Subroutine get_list_name_for_object_type: not called CC=1 SCAR=6.9
Pod documented
95 0 my ($self, $object_type) = @_;
96 0 my $list_accessor = $self->every_hash('LIST_ACCESSOR_FOR_OBJECT_TYPE');
97 0 assert_defined my $method = $list_accessor->{$object_type},
98 "unknown payload object type [$object_type]";
99 0 $method;
100 }
101  
102 0 ▶sub get_list_for_object_type {
Subroutine get_list_for_object_type: not called CC=2 SCAR=17.9
Pod documented
103 0 my ($self, $object_type) = @_;
104 0 our %cache_list_name_for_object_type;
105 0 ▶ my $method = $cache_list_name_for_object_type{$object_type} ||=
Condition0%0/3
$Data::Conveyor::Ticket::Payload::cache_list_name_for_object_type{$object_type} ||= $self->get_list_name_for_object_type($object_type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$Data::Conveyor::Ticket::Payload::cache_list_name_for_object_type{$object_type} ||= $self->get_list_name_for_object_type($object_type)
$Data::Conveyor::Ticket::Payload::cache_list_name_for_object_type{$object_type} $self->get_list_name_for_object_type($object_type)
Truth table0%0/3
A ||= B
A= $Data::Conveyor::Ticket::Payload::cache_list_name_for_object_type{$object_type}B= $self->get_list_name_for_object_type($object_type)
ABresult
1X1
011
000
106 $self->get_list_name_for_object_type($object_type);
107 0 $self->$method;
108 }
109  
110 # Take a list of payload items and add it to the appropriate array slots in
111 # the payload object
112 0 ▶sub add_items_from_list {
Subroutine add_items_from_list: not called CC=3 SCAR=24.8
Pod documented
113 0 my $self = shift;
114 0 for my $item (flatten(@_)) {
115 0 (my $factory_type = $item->get_my_factory_type) =~ s/^payload_//;
116 0 ▶ if ($factory_type eq 'common') {
Branch: 1 branch
BranchTrueFalseTotal
if ($factory_type eq "common") 0 0 0
117 0 $self->common($item);
118 0 next;
119 }
120 0 my $list_accessor = $self->get_list_name_for_object_type($factory_type);
121 0 my $push_method = $list_accessor . '_push';
122 0 $self->$push_method($item);
123 }
124 }
125  
126 0 ▶sub get_transactions_with_data_object_type {
Subroutine get_transactions_with_data_object_type: not called CC=1 SCAR=6.9
Pod documented
127 0 my ($self, $object_type) = @_;
128 0 grep { $_->data->object_type eq $object_type } $self->transactions;
129 }
130  
131 0 ▶sub get_transactions_with_data_object_type_and_cmd {
Subroutine get_transactions_with_data_object_type_and_cmd: not called CC=1 SCAR=6.9
Pod documented
132 0 my ($self, $object_type, $cmd) = @_;
133 0 grep { $_->data->command eq $cmd }
134 $self->get_transactions_with_data_object_type($object_type);
135 }
136  
137 0 ▶sub check {
Subroutine check: not called CC=4 SCAR=30.0
Pod documented
138 0 my ($self, $ticket) = @_;
139  
140 # check object limits; also check the payload items while we're at it
141 0 for my $object_type ($self->delegate->OT) {
142 0 my $limit =
143 $self->delegate->get_object_limit($ticket->type, $object_type);
144 0 my $index;
145 0 for my $item ($self->get_list_for_object_type($object_type)) {
146 0 $index++;
147  
148 # Ask the business object to check itself, accumulating exceptions
149 # into the business object's exception container.
150 0 $item->check($ticket);
151 0 ▶ next if $index <= $limit;
Branch: 1 branch
BranchTrueFalseTotal
if $index <= $limit 0 0 0
152 0 $item->exception_container->record(
153 'Data::Conveyor::Exception::ObjectLimitExceeded',
154 ticket_type => $ticket->type,
155 object_type => $object_type,
156 limit => $limit,
157 );
158 }
159 }
160 0 $self->common->check($ticket);
161 }
162  
163 # determines the overall payload rc
164 0 ▶sub rc {
Subroutine rc: not called CC=3 SCAR=24.8
Pod documented
165 0 my ($self, $ticket) = @_;
166  
167 # Start with RC_OK; if a stage wants to use another default rc, it can do
168 # so by setting the common payload item's default_rc.
169 0 my $rc =
170 $self->delegate->make_obj('value_ticket_rc', $self->delegate->RC_OK) +
171 $self->common->rc($ticket);
172 0 for my $object_type ($self->delegate->OT) {
173 $rc += $_->rc($ticket)
174 0 for $self->get_list_for_object_type($object_type);
175 }
176 0 $rc;
177 }
178  
179 # determines the overall payload status
180 0 ▶sub status {
Subroutine status: not called CC=3 SCAR=24.8
Pod documented
181 0 my ($self, $ticket) = @_;
182  
183 # Start with TS_RUNNING; if a stage wants to use another default status,
184 # it can do so by setting the common payload item's default_status.
185 0 my $status =
186 $self->delegate->make_obj('value_ticket_status',
187 $self->delegate->TS_RUNNING) + $self->common->status($ticket);
188 0 for my $object_type ($self->delegate->OT) {
189 $status += $_->status($ticket)
190 0 for $self->get_list_for_object_type($object_type);
191 }
192 0 $status;
193 }
194  
195 0 ▶sub update_transaction_stati {
Subroutine update_transaction_stati: not called CC=2 SCAR=17.9
Pod documented
196 0 my ($self, $ticket) = @_;
197 0 $_->transaction->update_status($ticket) for $self->transactions;
198 }
199  
200 0 ▶sub filter_exceptions_by_rc {
Subroutine filter_exceptions_by_rc: not called CC=3 SCAR=24.8
Pod documented
201 0 my ($self, $ticket, @filter) = @_;
202 0 my $result = $self->delegate->make_obj('exception_container');
203 0 for my $object_type ($self->delegate->OT) {
204 0 for my $payload_item ($self->get_list_for_object_type($object_type)) {
205 0 $result->items_push(
206 $payload_item->exception_container->filter_exceptions_by_rc(
207 $ticket, @filter
208 )
209 );
210 }
211 }
212 $result->items_push(
213 0 $self->common->exception_container->filter_exceptions_by_rc(
214 $ticket, @filter
215 )
216 );
217 0 $result;
218 }
219  
220 0 ▶sub filter_exceptions_by_status {
Subroutine filter_exceptions_by_status: not called CC=3 SCAR=24.8
Pod documented
221 0 my ($self, $ticket, @filter) = @_;
222 0 my $result = $self->delegate->make_obj('exception_container');
223 0 for my $object_type ($self->delegate->OT) {
224 0 for my $payload_item ($self->get_list_for_object_type($object_type)) {
225 0 $result->items_push(
226 $payload_item->exception_container->filter_exceptions_by_status(
227 $ticket, @filter
228 )
229 );
230 }
231 }
232 $result->items_push(
233 0 $self->common->exception_container->filter_exceptions_by_status(
234 $ticket, @filter
235 )
236 );
237 0 $result;
238 }
239  
240 0 ▶sub get_all_exceptions {
Subroutine get_all_exceptions: not called CC=3 SCAR=24.8
Pod documented
241 0 my $self = shift;
242 0 my $result = $self->delegate->make_obj('exception_container');
243 0 for my $object_type ($self->delegate->OT) {
244 0 for my $payload_item ($self->get_list_for_object_type($object_type)) {
245 0 $result->items_push($payload_item->exception_container->items);
246 }
247 }
248 0 $result->items_push($self->common->exception_container->items);
249 0 $result->delete_duplicate_exceptions; # returns $result
250 }
251  
252 0 ▶sub clear_all_exceptions {
Subroutine clear_all_exceptions: not called CC=3 SCAR=24.8
Pod documented
253 0 my $self = shift;
254 0 for my $object_type ($self->delegate->OT) {
255 0 for my $payload_item ($self->get_list_for_object_type($object_type)) {
256 0 $payload_item->exception_container->clear_items;
257 }
258 }
259 }
260  
261 # Iterates over all payload items and deletes all exceptions whose uuid is one
262 # of those given in the argument list
263 0 ▶sub delete_exceptions_by_uuid {
Subroutine delete_exceptions_by_uuid: not called CC=3 SCAR=24.8
Pod documented
264 0 my ($self, @uuid) = @_;
265 0 for my $object_type ($self->delegate->OT) {
266 0 for my $payload_item ($self->get_list_for_object_type($object_type)) {
267 0 $payload_item->exception_container->delete_by_uuid(@uuid);
268 }
269 }
270 }
271  
272 0 ▶sub delete_implicit_items {
Subroutine delete_implicit_items: not called CC=2 SCAR=17.9
Pod documented
273 0 my $self = shift;
274 0 for my $object_type ($self->delegate->OT) {
275 0 my $list_name = $self->get_list_name_for_object_type($object_type);
276 0 $self->$list_name([ grep { !$_->implicit } $self->$list_name ]);
277 }
278 }
279  
280 0 ▶sub prepare_comparable {
Subroutine prepare_comparable: not called CC=2 SCAR=17.9
Pod documented
281 0 my $self = shift;
282 0 $self->SUPER::prepare_comparable(@_);
283 0 $self->version($self->delegate->PAYLOAD_VERSION);
284  
285 # Touch various accessors that will autovivify hash keys so we can be sure
286 # they exist, which is a kind of normalization for the purpose of
287 # comparing two objects of this class.
288 0 $self->common;
289 0 $self->transactions;
290 0 $self->locks;
291  
292 # Touch the items of all exception containers so comparsions work (if the
293 # ticket is stored, the items of all exception containers at least exist).
294 0 $self->get_all_exceptions;
295 0 for my $object_type ($self->delegate->OT) {
296 0 my $list_name = $self->get_list_name_for_object_type($object_type);
297 0 $self->$list_name;
298 }
299 }
300  
301 0 ▶sub apply_instruction_containers {
Subroutine apply_instruction_containers: not called CC=3 SCAR=24.8
Pod documented
302 0 my $self = shift;
303 0 for my $object_type ($self->delegate->OT) {
304 0 for my $payload_item ($self->get_list_for_object_type($object_type)) {
305 0 $payload_item->apply_instruction_container;
306 }
307 }
308 }
309  
310 # Override this method to handle different payload versions: A payload may
311 # have been written months ago, but in the meantime the code might have
312 # changed. Therefore the old payload needs to be adapted to work with the new
313 # code.
314 0 ▶sub upgrade { }
Subroutine upgrade: not called CC=1 SCAR=0.0
Pod documented
315 1 1;
316  
317  
318 __END__
« Conveyor/Charset/ViaHash.pm ↑ Summary Conveyor/Storage/DBI.pm »