File Coverage

blib/lib/Biblio/ILL/ISO/Returned.pm
Criterion Covered Total %
statement 64 100 64.0
branch 16 52 30.7
condition 1 6 16.6
subroutine 13 16 81.2
pod 13 13 100.0
total 107 187 57.2


line stmt bran cond sub pod time code
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     2   5580 use Biblio::ILL::ISO::ISO;
  2         5  
  2         61  
10 2     2   12 use Carp;
  2         4  
  2         223  
11              
12             =head1 VERSION
13              
14             Version 0.02
15              
16             =cut
17              
18             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     2   3183 BEGIN{@ISA = qw ( Biblio::ILL::ISO::ISO ); }
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             sub new {
87 2     2 1 16 my $class = shift;
88 2         4 my $self = {};
89              
90 2 50       7 Biblio::ILL::ISO::ISO::_init() if (not $Biblio::ILL::ISO::ISO::_asn_initialized);
91 2         5 $self->{"ASN_TYPE"} = "Returned";
92              
93 2   33     12 bless($self, ref($class) || $class);
94 2         11 return ($self);
95             }
96              
97              
98             #---------------------------------------------------------------
99             #
100             #---------------------------------------------------------------
101             sub as_pretty_string {
102 0     0 1 0 my $self = shift;
103              
104 0         0 foreach my $key (sort keys %$self) {
105 0 0       0 if ($key ne "ASN_TYPE") {
106 0         0 print "\n[$key]\n";
107 0         0 print $self->{$key}->as_pretty_string();
108             }
109             }
110 0         0 return;
111             }
112              
113             #---------------------------------------------------------------
114             # This will return a structure usable by Convert::ASN1
115             #---------------------------------------------------------------
116             sub as_asn {
117 1     1 1 3 my $self = shift;
118              
119 1         2 my %h = ();
120 1         10 foreach my $key (sort keys %$self) {
121 9 100       20 if ($key ne "ASN_TYPE") {
122             #print "\n[$key]\n";
123 8         26 $h{$key} = $self->{$key}->as_asn();
124             }
125             }
126 1         5 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             sub from_asn {
153 0     0 1 0 my $self = shift;
154 0         0 my $href = shift;
155              
156 0         0 foreach my $k (keys %$href) {
157              
158 0 0 0     0 if ($k =~ /^protocol-version-num$/) {
    0          
    0          
    0          
    0          
    0          
    0          
    0          
159 0         0 $self->{$k} = new Biblio::ILL::ISO::ProtocolVersionNum();
160 0         0 $self->{$k}->from_asn($href->{$k});
161              
162             } elsif ($k =~ /^transaction-id$/) {
163 0         0 $self->{$k} = new Biblio::ILL::ISO::TransactionId();
164 0         0 $self->{$k}->from_asn($href->{$k});
165              
166             } elsif ($k =~ /^service-date-time$/) {
167 0         0 $self->{$k} = new Biblio::ILL::ISO::ServiceDateTime();
168 0         0 $self->{$k}->from_asn($href->{$k});
169              
170             } elsif (($k =~ /^requester-id$/)
171             || ($k =~ /^responder-id$/)
172             ) {
173 0         0 $self->{$k} = new Biblio::ILL::ISO::SystemId();
174 0         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         0 $self->{$k} = new Biblio::ILL::ISO::ISODate();
183 0         0 $self->{$k}->from_asn($href->{$k});
184              
185             } elsif ($k =~ /^returned-via$/) {
186 0         0 $self->{$k} = new Biblio::ILL::ISO::TransportationMode();
187 0         0 $self->{$k}->from_asn($href->{$k});
188              
189             } elsif ($k =~ /^insured-for$/) {
190 0         0 $self->{$k} = new Biblio::ILL::ISO::Amount();
191 0         0 $self->{$k}->from_asn($href->{$k});
192              
193             } elsif ($k =~ /^requester-note$/) {
194 0         0 $self->{$k} = new Biblio::ILL::ISO::ILLString();
195 0         0 $self->{$k}->from_asn($href->{$k});
196              
197             } else {
198 0         0 croak "invalid " . ref($self) . " element: [$k]";
199             }
200              
201             }
202 0         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             sub set_protocol_version_num {
219 1     1 1 6 my $self = shift;
220 1         3 my ($parm) = shift;
221              
222 1 50       3 croak "missing protocol-version-num" unless $parm;
223              
224 1         6 $self->{"protocol-version-num"} = new Biblio::ILL::ISO::ProtocolVersionNum($parm);
225              
226 1         3 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             sub set_transaction_id {
247 1     1 1 5 my $self = shift;
248 1         3 my ($parm) = shift;
249              
250 1 50       4 croak "missing transaction-id" unless $parm;
251 1 50       5 croak "invalid transaction-id" unless (ref($parm) eq "Biblio::ILL::ISO::TransactionId");
252              
253 1         2 $self->{"transaction-id"} = $parm;
254              
255 1         3 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             sub set_service_date_time {
277 1     1 1 10 my $self = shift;
278 1         9 my ($sdt) = shift;
279              
280 1 50       3 croak "missing service-date-time" unless $sdt;
281 1 50       4 croak "invalid service-date-time" unless (ref($sdt) eq "Biblio::ILL::ISO::ServiceDateTime");
282              
283 1         3 $self->{"service-date-time"} = $sdt;
284              
285 1         3 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             sub set_requester_id {
306 2     2 1 8 my $self = shift;
307 2         3 my ($parm) = shift;
308              
309 2 50       5 croak "missing requester-id" unless $parm;
310 2 50       6 croak "invalid requester-id" unless (ref($parm) eq "Biblio::ILL::ISO::SystemId");
311              
312 2         3 $self->{"requester-id"} = $parm;
313              
314 2         5 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             sub set_responder_id {
334 0     0 1 0 my $self = shift;
335 0         0 my ($parm) = shift;
336              
337 0 0       0 croak "missing responder-id" unless $parm;
338 0 0       0 croak "invalid responder-id" unless (ref($parm) eq "Biblio::ILL::ISO::SystemId");
339              
340 0         0 $self->{"responder-id"} = $parm;
341              
342 0         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             sub set_date_returned {
378 1     1 1 6 my $self = shift;
379 1         3 my ($parm) = shift;
380              
381 1 50       3 if (ref($parm) eq "Biblio::ILL::ISO::ISODate") {
382 1         3 $self->{"date-returned"} = $parm;
383             } else {
384 0         0 $self->{"date-returned"} = new Biblio::ILL::ISO::ISODate($parm);
385             }
386              
387 1         3 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             sub set_returned_via {
407 1     1 1 5 my $self = shift;
408 1         2 my ($parm) = shift;
409              
410 1 50       11 croak "missing returned-via" unless $parm;
411 1 50       4 croak "invalid returned-via" unless (ref($parm) eq "Biblio::ILL::ISO::TransportationMode");
412              
413 1         3 $self->{"returned-via"} = $parm;
414              
415 1         3 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             sub set_insured_for {
436 1     1 1 5 my $self = shift;
437 1         2 my ($parm) = shift;
438              
439 1 50       4 if (ref($parm) eq "Biblio::ILL::ISO::Amount") {
440 1         9 $self->{"insured-for"} = $parm;
441             } else {
442 0         0 $self->{"insured-for"} = new Biblio::ILL::ISO::Amount($parm);
443             }
444              
445 1         2 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             sub set_requester_note {
464 1     1 1 6 my $self = shift;
465 1         2 my ($parm) = shift;
466              
467 1 50       4 croak "missing requester-note" unless $parm;
468 1 50       4 croak "invalid requester-note" unless (ref($parm) eq "Biblio::ILL::ISO::ILLString");
469              
470 1         3 $self->{"requester-note"} = $parm;
471              
472 1         8 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,
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             1;