lib/Biblio/ILL/ISO/Returned.pm

filter: Statementstmt 64.7% 66 / 102 Branchbran 30.7% 16 / 52 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 81.2% 13 / 16 Podpod 100% 13 / 13 totaltotal 56.4% 109 / 193 CC 32 SCAR 35.3
CC
32
Cov
52%
from_asn
132.0
as_pretty_string
12.0
set_responder_id
12.0
CRAP 34.1
« lib/Biblio/ILL/ISO/StatusOrErrorReport.pm ↑ Summary lib/Biblio/ILL/ISO/Received.pm »
1 package Biblio::ILL::ISO::Returned;
2  
3 =head1 NAME
4  
5 Biblio::ILL::ISO::Returned - Perl extension for handling ISO 10161 interlibrary loan Returned messages
6  
7 =cut
8  
9 2 ▶use Biblio::ILL::ISO::ISO;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 VERSION
13  
14 Version 0.02
15  
16 =cut
17  
18 2 our $VERSION = '0.02';
19 #---------------------------------------------------------------------------
20 # Mods
21 # 0.02 - 2003.09.07 - fixed the POD
22 # 0.01 - 2003.08.11 - original version
23 #---------------------------------------------------------------------------
24  
25 =head1 DESCRIPTION
26  
27 Biblio::ILL::ISO::Returned is a derivation of the abstract
28 Biblio::ILL::ISO::ISO object, and handles the Returned message type.
29  
30 =head1 EXPORT
31  
32 None.
33  
34 =head1 ERROR HANDLING
35  
36 Each of the set_() methods will croak on missing or invalid parameters.
37  
38 =cut
39  
40 2 ▶BEGIN{@ISA = qw ( Biblio::ILL::ISO::ISO ); }
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 =head1 FROM THE ASN DEFINITION
43  
44 Returned ::= [APPLICATION 10] SEQUENCE {
45 protocol-version-num [0] IMPLICIT INTEGER, -- {
46 -- version-1 (1),
47 -- version-2 (2)
48 -- },
49 transaction-id [1] IMPLICIT Transaction-Id,
50 service-date-time [2] IMPLICIT Service-Date-Time,
51 requester-id [3] IMPLICIT System-Id OPTIONAL,
52 -- mandatory when using store-and-forward communications
53 -- optional when using connection-oriented communications
54 responder-id [4] IMPLICIT System-Id OPTIONAL,
55 -- mandatory when using store-and-forward communications
56 -- optional when using connection-oriented communications
57 -- DC - 'EXTERNAL' definition (see Supplemental-Item-Description)
58 -- supplemental-item-description [17] IMPLICIT Supplemental-Item-Description OPTIONAL,
59 date-returned [37] IMPLICIT ISO-Date,
60 returned-via [38] Transportation-Mode OPTIONAL,
61 insured-for [39] IMPLICIT Amount OPTIONAL,
62 requester-note [46] ILL-String OPTIONAL,
63 returned-extensions [49] IMPLICIT SEQUENCE OF Extension OPTIONAL
64 }
65  
66 =cut
67  
68 =head1 CONSTRUCTORS
69  
70 new()
71  
72 Base constructor for the class. It just returns a completely
73 empty message object, which you'll need to populate with the
74 various set_() methods, or use the read() method to read a
75 Returned message from a file (followed by a call to
76 from_asn() to turn the read's returned hash into a proper
77 Returned message.
78  
79 The constructor also initializes the Convert::ASN1 if it
80 hasn't been initialized.
81  
82 =cut
83 #---------------------------------------------------------------
84 #
85 #---------------------------------------------------------------
86 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.6
Pod documented
87 2 my $class = shift;
88 2 my $self = {};
89  
90 2 ▶ Biblio::ILL::ISO::ISO::_init() if (not $Biblio::ILL::ISO::ISO::_asn_initialized);
Branch: 1 branch
BranchTrueFalseTotal
unless $Biblio::ILL::ISO::ISO::_asn_initialized 0 2 2
91 2 $self->{"ASN_TYPE"} = "Returned";
92  
93 2 ▶ bless($self, ref($class) || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
94 2 return ($self);
95 }
96  
97  
98 #---------------------------------------------------------------
99 #
100 #---------------------------------------------------------------
101 0 ▶sub as_pretty_string {
Subroutine as_pretty_string: not called CC=3 SCAR=24.8
Pod documented
102 0 my $self = shift;
103  
104 0 foreach my $key (sort keys %$self) {
105 0 ▶ if ($key ne "ASN_TYPE") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key ne "ASN_TYPE") 0 0 0
106 0 print "\n[$key]\n";
107 0 print $self->{$key}->as_pretty_string();
108 }
109 }
110 0 return;
111 }
112  
113 #---------------------------------------------------------------
114 # This will return a structure usable by Convert::ASN1
115 #---------------------------------------------------------------
116 1 ▶sub as_asn {
Subroutine as_asn: called CC=3 SCAR=11.0
Pod documented
117 1 my $self = shift;
118  
119 1 my %h = ();
120 1 foreach my $key (sort keys %$self) {
121 9 ▶ if ($key ne "ASN_TYPE") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key ne "ASN_TYPE") 8 1 9
122 #print "\n[$key]\n";
123 8 $h{$key} = $self->{$key}->as_asn();
124 }
125 }
126 1 return \%h;
127 }
128  
129 =head1 METHODS
130  
131 For any example code, assume the following:
132 my $msg = new Biblio::ILL::ISO::Returned;
133  
134 =cut
135  
136 #---------------------------------------------------------------
137 #
138 #---------------------------------------------------------------
139 =head1
140  
141 =head2 from_asn($href)
142  
143 To read a message from a file, use the following:
144  
145 my $href = $msg->read("msg_10.returned.ber");
146 $msg = $msg->from_asn($href);
147  
148 The from_asn() method turns the hash returned from read() into
149 a proper message-type object.
150  
151 =cut
152 0 ▶sub from_asn {
Subroutine from_asn: not called CC=11 SCAR=48.8
Pod documented
153 0 my $self = shift;
154 0 my $href = shift;
155  
156 0 foreach my $k (keys %$href) {
157  
158 0 ▶ if ($k =~ /^protocol-version-num$/) {
Branch: 8 branches
BranchTrueFalseTotal
if ($k =~ /^protocol-version-num$/) { } 0 0 0
elsif ($k =~ /^transaction-id$/) { } 0 0 0
elsif ($k =~ /^service-date-time$/) { } 0 0 0
elsif ($k =~ /^requester-id$/ or $k =~ /^responder-id$/) { } 0 0 0
elsif ($k =~ /^date-returned$/) { } 0 0 0
elsif ($k =~ /^returned-via$/) { } 0 0 0
elsif ($k =~ /^insured-for$/) { } 0 0 0
elsif ($k =~ /^requester-note$/) { } 0 0 0
159 0 $self->{$k} = new Biblio::ILL::ISO::ProtocolVersionNum();
160 0 $self->{$k}->from_asn($href->{$k});
161  
162 } elsif ($k =~ /^transaction-id$/) {
163 0 $self->{$k} = new Biblio::ILL::ISO::TransactionId();
164 0 $self->{$k}->from_asn($href->{$k});
165  
166 } elsif ($k =~ /^service-date-time$/) {
167 0 $self->{$k} = new Biblio::ILL::ISO::ServiceDateTime();
168 0 $self->{$k}->from_asn($href->{$k});
169  
170 ▶ } elsif (($k =~ /^requester-id$/)
Condition0%0/3
$k =~ /^requester-id$/ or $k =~ /^responder-id$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$k =~ /^requester-id$/ or $k =~ /^responder-id$/
$k =~ /^requester-id$/ $k =~ /^responder-id$/
Truth table0%0/3
A or B
A= $k =~ /^requester-id$/B= $k =~ /^responder-id$/
ABresult
1X1
011
000
171 || ($k =~ /^responder-id$/)
172 ) {
173 0 $self->{$k} = new Biblio::ILL::ISO::SystemId();
174 0 $self->{$k}->from_asn($href->{$k});
175  
176 # This is EXTERNAL, which we don't handle.
177 #} elsif ($k =~ /^supplemental-item-description$/) {
178 # $self->{$k} = new Biblio::ILL::ISO::SupplementalItemDescription();
179 # $self->{$k}->from_asn($href->{$k});
180  
181 } elsif ($k =~ /^date-returned$/) {
182 0 $self->{$k} = new Biblio::ILL::ISO::ISODate();
183 0 $self->{$k}->from_asn($href->{$k});
184  
185 } elsif ($k =~ /^returned-via$/) {
186 0 $self->{$k} = new Biblio::ILL::ISO::TransportationMode();
187 0 $self->{$k}->from_asn($href->{$k});
188  
189 } elsif ($k =~ /^insured-for$/) {
190 0 $self->{$k} = new Biblio::ILL::ISO::Amount();
191 0 $self->{$k}->from_asn($href->{$k});
192  
193 } elsif ($k =~ /^requester-note$/) {
194 0 $self->{$k} = new Biblio::ILL::ISO::ILLString();
195 0 $self->{$k}->from_asn($href->{$k});
196  
197 } else {
198 0 croak "invalid " . ref($self) . " element: [$k]";
199 }
200  
201 }
202 0 return $self;
203 }
204  
205 #---------------------------------------------------------------
206 #
207 #---------------------------------------------------------------
208 =head1
209  
210 =head2 set_protocol_version_num($pvn)
211  
212 Sets the protocol version number.
213 Acceptable parameter values are the strings:
214 version-1
215 version-2
216  
217 =cut
218 1 ▶sub set_protocol_version_num {
Subroutine set_protocol_version_num: called CC=2 SCAR=7.0
Pod documented
219 1 my $self = shift;
220 1 my ($parm) = shift;
221  
222 1 ▶ croak "missing protocol-version-num" unless $parm;
Branch: 1 branch
BranchTrueFalseTotal
unless $parm 0 1 1
223  
224 1 $self->{"protocol-version-num"} = new Biblio::ILL::ISO::ProtocolVersionNum($parm);
225  
226 1 return;
227 }
228  
229 #---------------------------------------------------------------
230 #
231 #---------------------------------------------------------------
232 =head1
233  
234 =head2 set_transaction_id($tid)
235  
236 Sets the message's transaction-id.
237 Expects a valid Biblio::ILL::ISO::TransactionId.
238  
239 my $tid = new Biblio::ILL::ISO::TransactionId("PLS","001","",
240 new Biblio::ILL::ISO::SystemId("MWPL"));
241 $msg->set_transaction_id($tid);
242  
243 This is a mandatory field.
244  
245 =cut
246 1 ▶sub set_transaction_id {
Subroutine set_transaction_id: called CC=3 SCAR=11.2
Pod documented
247 1 my $self = shift;
248 1 my ($parm) = shift;
249  
250 1 ▶ croak "missing transaction-id" unless $parm;
Branch: 1 branch
BranchTrueFalseTotal
unless $parm 0 1 1
251 1 ▶ croak "invalid transaction-id" unless (ref($parm) eq "Biblio::ILL::ISO::TransactionId");
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parm eq "Biblio::ILL::ISO::TransactionId" 0 1 1
252  
253 1 $self->{"transaction-id"} = $parm;
254  
255 1 return;
256 }
257  
258 #---------------------------------------------------------------
259 #
260 #---------------------------------------------------------------
261 =head1
262  
263 =head2 set_service_date_time($sdt)
264  
265 Sets the message's service-date-time.
266 Expects a valid Biblio::ILL::ISO::ServiceDateTime.
267  
268 my $dt_this = new Biblio::ILL::ISO::DateTime("20030623","114400");
269 my $dt_orig = new Biblio::ILL::ISO::DateTime("20030623","114015")
270 my $sdt = new Biblio::ILL::ISO::ServiceDateTime( $dt_this, $dt_orig);
271 $msg->set_service_date_time($sdt);
272  
273 This is a mandatory field.
274  
275 =cut
276 1 ▶sub set_service_date_time {
Subroutine set_service_date_time: called CC=3 SCAR=11.2
Pod documented
277 1 my $self = shift;
278 1 my ($sdt) = shift;
279  
280 1 ▶ croak "missing service-date-time" unless $sdt;
Branch: 1 branch
BranchTrueFalseTotal
unless $sdt 0 1 1
281 1 ▶ croak "invalid service-date-time" unless (ref($sdt) eq "Biblio::ILL::ISO::ServiceDateTime");
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sdt eq "Biblio::ILL::ISO::ServiceDateTime" 0 1 1
282  
283 1 $self->{"service-date-time"} = $sdt;
284  
285 1 return;
286 }
287  
288 #---------------------------------------------------------------
289 #
290 #---------------------------------------------------------------
291 =head1
292  
293 =head2 set_requester_id($reqid)
294  
295 Sets the message's requester-id.
296 Expects a valid Biblio::ILL::ISO::SystemId.
297  
298 my $reqid = new Biblio::ILL::ISO::SystemId();
299 $reqid->set_person_name("David A. Christensen");
300 $msg->set_requester_id($reqid);
301  
302 This is an optional field.
303  
304 =cut
305 2 ▶sub set_requester_id {
Subroutine set_requester_id: called CC=3 SCAR=11.2
Pod documented
306 2 my $self = shift;
307 2 my ($parm) = shift;
308  
309 2 ▶ croak "missing requester-id" unless $parm;
Branch: 1 branch
BranchTrueFalseTotal
unless $parm 0 2 2
310 2 ▶ croak "invalid requester-id" unless (ref($parm) eq "Biblio::ILL::ISO::SystemId");
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parm eq "Biblio::ILL::ISO::SystemId" 0 2 2
311  
312 2 $self->{"requester-id"} = $parm;
313  
314 2 return;
315 }
316  
317 #---------------------------------------------------------------
318 #
319 #---------------------------------------------------------------
320 =head1
321  
322 =head2 set_responder_id($resid)
323  
324 Sets the message's responder-id.
325 Expects a valid Biblio::ILL::ISO::SystemId.
326  
327 my $resid = new Biblio::ILL::ISO::SystemId("MWPL");
328 $msg->set_responder_id($resid);
329  
330 This is an optional field.
331  
332 =cut
333 0 ▶sub set_responder_id {
Subroutine set_responder_id: not called CC=3 SCAR=24.8
Pod documented
334 0 my $self = shift;
335 0 my ($parm) = shift;
336  
337 0 ▶ croak "missing responder-id" unless $parm;
Branch: 1 branch
BranchTrueFalseTotal
unless $parm 0 0 0
338 0 ▶ croak "invalid responder-id" unless (ref($parm) eq "Biblio::ILL::ISO::SystemId");
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parm eq "Biblio::ILL::ISO::SystemId" 0 0 0
339  
340 0 $self->{"responder-id"} = $parm;
341  
342 0 return;
343 }
344  
345 #---------------------------------------------------------------
346 # This is EXTERNAL, which we don't handle
347 #---------------------------------------------------------------
348 #sub set_supplemental_item_description {
349 # my $self = shift;
350 # my ($parm) = shift;
351 #
352 # croak "missing supplemental-item-description" unless $parm;
353 # croak "invalid supplemental-item-description" unless (ref($parm) eq "Biblio::ILL::ISO::SupplementalItemDescription");
354 #
355 # $self->{"supplemental-item-description"} = $parm;
356 #
357 # return;
358 #}
359  
360 #---------------------------------------------------------------
361 #
362 #---------------------------------------------------------------
363 =head1
364  
365 =head2 set_date_returned($dr)
366  
367 Sets the message's dat-returned.
368 Expects a valid Biblio::ILL::ISO::ISODate or a properly formatted
369 date string (YYYYMMDD).
370  
371 my $dr = new Biblio::ILL::ISO::ISODate("20030814");
372 $msg->set_date_returned($dr);
373  
374 This is a mandatory field.
375  
376 =cut
377 1 ▶sub set_date_returned {
Subroutine set_date_returned: called CC=2 SCAR=7.2
Pod documented
378 1 my $self = shift;
379 1 my ($parm) = shift;
380  
381 1 ▶ if (ref($parm) eq "Biblio::ILL::ISO::ISODate") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parm eq 'Biblio::ILL::ISO::ISODate') { } 1 0 1
382 1 $self->{"date-returned"} = $parm;
383 } else {
384 0 $self->{"date-returned"} = new Biblio::ILL::ISO::ISODate($parm);
385 }
386  
387 1 return;
388 }
389  
390 #---------------------------------------------------------------
391 #
392 #---------------------------------------------------------------
393 =head1
394  
395 =head2 set_returned_via($rv)
396  
397 Sets the message's returned-via.
398 Expects a valid Biblio::ILL::ISO::TransportationMode.
399  
400 my $rv = new Biblio::ILL::ISO::TransportationMode("Canada Post");
401 $msg->set_returned_via($rv);
402  
403 This is an optional field.
404  
405 =cut
406 1 ▶sub set_returned_via {
Subroutine set_returned_via: called CC=3 SCAR=11.2
Pod documented
407 1 my $self = shift;
408 1 my ($parm) = shift;
409  
410 1 ▶ croak "missing returned-via" unless $parm;
Branch: 1 branch
BranchTrueFalseTotal
unless $parm 0 1 1
411 1 ▶ croak "invalid returned-via" unless (ref($parm) eq "Biblio::ILL::ISO::TransportationMode");
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parm eq "Biblio::ILL::ISO::TransportationMode" 0 1 1
412  
413 1 $self->{"returned-via"} = $parm;
414  
415 1 return;
416 }
417  
418 #---------------------------------------------------------------
419 #
420 #---------------------------------------------------------------
421 =head1
422  
423 =head2 set_insured_for($ins)
424  
425 Sets the message's insured-for.
426 Expects a valid Biblio::ILL::ISO::Amount or a properly formatted
427 amount string.
428  
429 my $ins = new Biblio::ILL::ISO::Amount("123.45");
430 $msg->set_insured_for($ins);
431  
432 This is an optional field.
433  
434 =cut
435 1 ▶sub set_insured_for {
Subroutine set_insured_for: called CC=2 SCAR=7.2
Pod documented
436 1 my $self = shift;
437 1 my ($parm) = shift;
438  
439 1 ▶ if (ref($parm) eq "Biblio::ILL::ISO::Amount") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parm eq 'Biblio::ILL::ISO::Amount') { } 1 0 1
440 1 $self->{"insured-for"} = $parm;
441 } else {
442 0 $self->{"insured-for"} = new Biblio::ILL::ISO::Amount($parm);
443 }
444  
445 1 return;
446 }
447  
448 #---------------------------------------------------------------
449 #
450 #---------------------------------------------------------------
451 =head1
452  
453 =head2 set_requester_note($note)
454  
455 Sets the message's requester-note.
456 Expects a simple text string.
457  
458 $msg->set_requester_note("This is a requester note");
459  
460 This is an optional field.
461  
462 =cut
463 1 ▶sub set_requester_note {
Subroutine set_requester_note: called CC=3 SCAR=11.2
Pod documented
464 1 my $self = shift;
465 1 my ($parm) = shift;
466  
467 1 ▶ croak "missing requester-note" unless $parm;
Branch: 1 branch
BranchTrueFalseTotal
unless $parm 0 1 1
468 1 ▶ croak "invalid requester-note" unless (ref($parm) eq "Biblio::ILL::ISO::ILLString");
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parm eq "Biblio::ILL::ISO::ILLString" 0 1 1
469  
470 1 $self->{"requester-note"} = $parm;
471  
472 1 return;
473 }
474  
475 =head1 RELATED MODULES
476  
477 Biblio::ILL::ISO::ISO
478 Biblio::ILL::ISO::Request
479 Biblio::ILL::ISO::ForwardNotification
480 Biblio::ILL::ISO::Shipped
481 Biblio::ILL::ISO::Answer
482 Biblio::ILL::ISO::ConditionalReply
483 Biblio::ILL::ISO::Cancel
484 Biblio::ILL::ISO::CancelReply
485 Biblio::ILL::ISO::Received
486 Biblio::ILL::ISO::Recall
487 Biblio::ILL::ISO::Returned
488 Biblio::ILL::ISO::CheckedIn
489 Biblio::ILL::ISO::Overdue
490 Biblio::ILL::ISO::Renew
491 Biblio::ILL::ISO::RenewAnswer
492 Biblio::ILL::ISO::Lost
493 Biblio::ILL::ISO::Damaged
494 Biblio::ILL::ISO::Message
495 Biblio::ILL::ISO::StatusQuery
496 Biblio::ILL::ISO::StatusOrErrorReport
497 Biblio::ILL::ISO::Expired
498  
499 =cut
500  
501 =head1 SEE ALSO
502  
503 See the README for system design notes.
504  
505 For more information on Interlibrary Loan standards (ISO 10160/10161),
506 a good place to start is:
507  
508 http://www.nlc-bnc.ca/iso/ill/main.htm
509  
510 =cut
511  
512 =head1 AUTHOR
513  
514 David Christensen, <DChristensenSPAMLESS@westman.wave.ca>
515  
516 =cut
517  
518  
519 =head1 COPYRIGHT AND LICENSE
520  
521 Copyright 2003 by David Christensen
522  
523 This library is free software; you can redistribute it and/or modify it
524 under the same terms as Perl itself.
525  
526 =cut
527  
528 2 1;
« lib/Biblio/ILL/ISO/StatusOrErrorReport.pm ↑ Summary lib/Biblio/ILL/ISO/Received.pm »