File Coverage

blib/lib/Biblio/ILL/ISO/StatusOrErrorReport.pm
Criterion Covered Total %
statement 60 99 60.6
branch 16 52 30.7
condition 1 6 16.6
subroutine 12 16 75.0
pod 13 13 100.0
total 102 186 54.8


line stmt bran cond sub pod time code
1             package Biblio::ILL::ISO::StatusOrErrorReport;
2              
3             =head1 NAME
4              
5             Biblio::ILL::ISO::StatusOrErrorReport - Perl extension for handling ISO 10161 interlibrary loan
6             Status-Or-Error-Report messages
7              
8             =cut
9              
10 2     2   4653 use Biblio::ILL::ISO::ISO;
  2         7  
  2         68  
11 2     2   22 use Carp;
  2         7  
  2         433  
12              
13             =head1 VERSION
14              
15             Version 0.01
16              
17             =cut
18              
19             our $VERSION = '0.01';
20             #---------------------------------------------------------------------------
21             # Mods
22             # 0.01 - 2003.08.11 - original version
23             #---------------------------------------------------------------------------
24              
25             =head1 DESCRIPTION
26              
27             Biblio::ILL::ISO::StatusOrErrorReport is a derivation of the abstract
28             Biblio::ILL::ISO::ISO object, and handles the Status-Or-Error-Report 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   3576 BEGIN{@ISA = qw ( Biblio::ILL::ISO::ISO ); }
41              
42             =head1 FROM THE ASN DEFINITION
43            
44             Status-Or-Error-Report ::= [APPLICATION 19] 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             reason-no-report [43] IMPLICIT Reason-No-Report OPTIONAL,
58             -- mandatory if no report is present;
59             -- not present otherwise
60             status-report [44] IMPLICIT Status-Report OPTIONAL,
61             error-report [45] IMPLICIT Error-Report OPTIONAL,
62             note [46] ILL-String OPTIONAL,
63             status-or-error-report-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             Status-Or-Error-Report message from a file (followed by a call to
76             from_asn() to turn the read's returned hash into a proper
77             StatusOrErrorReport message.
78              
79             The constructor also initializes the Convert::ASN1 if it
80             hasn't been initialized.
81              
82             =cut
83              
84             #---------------------------------------------------------------
85             #
86             #---------------------------------------------------------------
87             sub new {
88 2     2 1 19 my $class = shift;
89 2         4 my $self = {};
90              
91 2 50       4 Biblio::ILL::ISO::ISO::_init() if (not $Biblio::ILL::ISO::ISO::_asn_initialized);
92 2         4 $self->{"ASN_TYPE"} = "Status-Or-Error-Report";
93              
94 2   33     10 bless($self, ref($class) || $class);
95 2         5 return ($self);
96             }
97              
98              
99             #---------------------------------------------------------------
100             #
101             #---------------------------------------------------------------
102             sub as_pretty_string {
103 0     0 1 0 my $self = shift;
104              
105 0         0 foreach my $key (sort keys %$self) {
106 0 0       0 if ($key ne "ASN_TYPE") {
107 0         0 print "\n[$key]\n";
108 0         0 print $self->{$key}->as_pretty_string();
109             }
110             }
111 0         0 return;
112             }
113              
114             #---------------------------------------------------------------
115             # This will return a structure usable by Convert::ASN1
116             #---------------------------------------------------------------
117             sub as_asn {
118 1     1 1 3 my $self = shift;
119              
120 1         3 my %h = ();
121 1         12 foreach my $key (sort keys %$self) {
122 8 100       22 if ($key ne "ASN_TYPE") {
123             #print "\n[$key]\n";
124 7         35 $h{$key} = $self->{$key}->as_asn();
125             }
126             }
127 1         5 return \%h;
128             }
129              
130             =head1 METHODS
131              
132             For any example code, assume the following:
133             my $msg = new Biblio::ILL::ISO::StatusOrErrorReport;
134              
135             =cut
136              
137             #---------------------------------------------------------------
138             #
139             #---------------------------------------------------------------
140             =head1
141              
142             =head2 from_asn($href)
143              
144             To read a message from a file, use the following:
145              
146             my $href = $msg->read("msg_18.status-or-error-report.ber");
147             $msg = $msg->from_asn($href);
148              
149             The from_asn() method turns the hash returned from read() into
150             a proper message-type object.
151              
152             =cut
153             sub from_asn {
154 0     0 1 0 my $self = shift;
155 0         0 my $href = shift;
156              
157 0         0 foreach my $k (keys %$href) {
158              
159 0 0 0     0 if ($k =~ /^protocol-version-num$/) {
    0          
    0          
    0          
    0          
    0          
    0          
    0          
160 0         0 $self->{$k} = new Biblio::ILL::ISO::ProtocolVersionNum();
161 0         0 $self->{$k}->from_asn($href->{$k});
162              
163             } elsif ($k =~ /^transaction-id$/) {
164 0         0 $self->{$k} = new Biblio::ILL::ISO::TransactionId();
165 0         0 $self->{$k}->from_asn($href->{$k});
166              
167             } elsif ($k =~ /^service-date-time$/) {
168 0         0 $self->{$k} = new Biblio::ILL::ISO::ServiceDateTime();
169 0         0 $self->{$k}->from_asn($href->{$k});
170              
171             } elsif (($k =~ /^requester-id$/)
172             || ($k =~ /^responder-id$/)
173             ) {
174 0         0 $self->{$k} = new Biblio::ILL::ISO::SystemId();
175 0         0 $self->{$k}->from_asn($href->{$k});
176              
177             } elsif ($k =~ /^reason-no-report$/) {
178 0         0 $self->{$k} = new Biblio::ILL::ISO::ReasonNoReport();
179 0         0 $self->{$k}->from_asn($href->{$k});
180              
181             } elsif ($k =~ /^status-report$/) {
182 0         0 $self->{$k} = new Biblio::ILL::ISO::StatusReport();
183 0         0 $self->{$k}->from_asn($href->{$k});
184              
185             } elsif ($k =~ /^error-report$/) {
186 0         0 $self->{$k} = new Biblio::ILL::ISO::ErrorReport();
187 0         0 $self->{$k}->from_asn($href->{$k});
188              
189             } elsif ($k =~ /^note$/) {
190 0         0 $self->{$k} = new Biblio::ILL::ISO::ILLString();
191 0         0 $self->{$k}->from_asn($href->{$k});
192              
193             } else {
194 0         0 croak "invalid " . ref($self) . " element: [$k]";
195             }
196              
197             }
198 0         0 return $self;
199             }
200              
201             #---------------------------------------------------------------
202             #
203             #---------------------------------------------------------------
204             =head1
205              
206             =head2 set_protocol_version_num($pvn)
207              
208             Sets the protocol version number.
209             Acceptable parameter values are the strings:
210             version-1
211             version-2
212              
213             =cut
214             sub set_protocol_version_num {
215 1     1 1 5 my $self = shift;
216 1         2 my ($parm) = shift;
217              
218 1 50       15 croak "missing protocol-version-num" unless $parm;
219              
220 1         9 $self->{"protocol-version-num"} = new Biblio::ILL::ISO::ProtocolVersionNum($parm);
221              
222 1         3 return;
223             }
224              
225             #---------------------------------------------------------------
226             #
227             #---------------------------------------------------------------
228             =head1
229              
230             =head2 set_transaction_id($tid)
231              
232             Sets the message's transaction-id.
233             Expects a valid Biblio::ILL::ISO::TransactionId.
234              
235             my $tid = new Biblio::ILL::ISO::TransactionId("PLS","001","",
236             new Biblio::ILL::ISO::SystemId("MWPL"));
237             $msg->set_transaction_id($tid);
238              
239             This is a mandatory field.
240              
241             =cut
242             sub set_transaction_id {
243 1     1 1 5 my $self = shift;
244 1         2 my ($parm) = shift;
245              
246 1 50       4 croak "missing transaction-id" unless $parm;
247 1 50       4 croak "invalid transaction-id" unless (ref($parm) eq "Biblio::ILL::ISO::TransactionId");
248              
249 1         2 $self->{"transaction-id"} = $parm;
250              
251 1         2 return;
252             }
253              
254             #---------------------------------------------------------------
255             #
256             #---------------------------------------------------------------
257             =head1
258              
259             =head2 set_service_date_time($sdt)
260              
261             Sets the message's service-date-time.
262             Expects a valid Biblio::ILL::ISO::ServiceDateTime.
263              
264             my $dt_this = new Biblio::ILL::ISO::DateTime("20030623","114400");
265             my $dt_orig = new Biblio::ILL::ISO::DateTime("20030623","114015")
266             my $sdt = new Biblio::ILL::ISO::ServiceDateTime( $dt_this, $dt_orig);
267             $msg->set_service_date_time($sdt);
268              
269             This is a mandatory field.
270              
271             =cut
272             sub set_service_date_time {
273 1     1 1 5 my $self = shift;
274 1         2 my ($sdt) = shift;
275              
276 1 50       4 croak "missing service-date-time" unless $sdt;
277 1 50       3 croak "invalid service-date-time" unless (ref($sdt) eq "Biblio::ILL::ISO::ServiceDateTime");
278              
279 1         2 $self->{"service-date-time"} = $sdt;
280              
281 1         2 return;
282             }
283              
284             #---------------------------------------------------------------
285             #
286             #---------------------------------------------------------------
287             =head1
288              
289             =head2 set_requester_id($reqid)
290              
291             Sets the message's requester-id.
292             Expects a valid Biblio::ILL::ISO::SystemId.
293              
294             my $reqid = new Biblio::ILL::ISO::SystemId();
295             $reqid->set_person_name("David A. Christensen");
296             $msg->set_requester_id($reqid);
297              
298             This is an optional field.
299              
300             =cut
301             sub set_requester_id {
302 1     1 1 6 my $self = shift;
303 1         2 my ($parm) = shift;
304              
305 1 50       13 croak "missing requester-id" unless $parm;
306 1 50       5 croak "invalid requester-id" unless (ref($parm) eq "Biblio::ILL::ISO::SystemId");
307              
308 1         2 $self->{"requester-id"} = $parm;
309              
310 1         3 return;
311             }
312              
313             #---------------------------------------------------------------
314             #
315             #---------------------------------------------------------------
316             =head1
317              
318             =head2 set_responder_id($resid)
319              
320             Sets the message's responder-id.
321             Expects a valid Biblio::ILL::ISO::SystemId.
322              
323             my $resid = new Biblio::ILL::ISO::SystemId("MWPL");
324             $msg->set_responder_id($resid);
325              
326             This is an optional field.
327              
328             =cut
329             sub set_responder_id {
330 1     1 1 7 my $self = shift;
331 1         2 my ($parm) = shift;
332              
333 1 50       3 croak "missing responder-id" unless $parm;
334 1 50       4 croak "invalid responder-id" unless (ref($parm) eq "Biblio::ILL::ISO::SystemId");
335              
336 1         2 $self->{"responder-id"} = $parm;
337              
338 1         2 return;
339             }
340              
341             #---------------------------------------------------------------
342             #
343             #---------------------------------------------------------------
344             =head1
345              
346             =head2 set_reason_no_report($rnr)
347              
348             Sets the message's reason-no-report.
349             Acceptable parameter values are the strings:
350             temporary
351             permanent
352              
353             This is an optional field.
354              
355             =cut
356             sub set_reason_no_report {
357 0     0 1 0 my $self = shift;
358 0         0 my ($parm) = shift;
359              
360 0         0 $self->{"reason-no-report"} = new Biblio::ILL::ISO::ReasonNoReport($parm);
361              
362 0         0 return;
363             }
364              
365             #---------------------------------------------------------------
366             #
367             #---------------------------------------------------------------
368             =head1
369              
370             =head2 set_status_report($sr)
371              
372             Sets the message's status-report.
373             Expects a valid Biblio::ILL::ISO::StatusReport.
374              
375             my $cs = new Biblio::ILL::ISO::CurrentState("sHIPPED");
376             my $hr = new Biblio::ILL::ISO::HistoryReport("20030811",
377             "fORWARD",
378             "20030813",
379             new Biblio::ILL::ISO::SystemId("MBOM"),
380             "20030815",
381             "Anne Author",
382             "A Title",
383             "",
384             "",
385             "loan",
386             new Biblio::ILL::ISO::TransactionResults("will-supply"),
387             "This is a history report."
388             );
389             my $sr = new Biblio::ILL::ISO::StatusReport($hr, $cs);
390             $msg->set_status_report($sr);
391              
392             This is an optional field.
393              
394             =cut
395             sub set_status_report {
396 1     1 1 5 my $self = shift;
397 1         4 my ($parm) = shift;
398              
399 1 50       8 croak "missing status-report" unless $parm;
400 1 50       4 croak "invalid status-report" unless (ref($parm) eq "Biblio::ILL::ISO::StatusReport");
401              
402 1         4 $self->{"status-report"} = $parm;
403              
404 1         3 return;
405             }
406              
407             #---------------------------------------------------------------
408             #
409             #---------------------------------------------------------------
410             =head1
411              
412             =head2 set_error_report($er)
413              
414             Sets the message's error-report.
415             Expects a valid Biblio::ILL::ISO::ErrorReport.
416              
417             my $tip = new Biblio::ILL::ISO::TransactionIdProblem("duplicate-transaction-id");
418             my $per = new Biblio::ILL::ISO::ProviderErrorReport( $tip );
419             my $er = new Biblio::ILL::ISO::ErrorReport("Some correlation information",
420             "provider",
421             $per,
422             );
423             $msg->set_error_report($er);
424              
425             This is an optional field.
426              
427             =cut
428             sub set_error_report {
429 0     0 1 0 my $self = shift;
430 0         0 my ($parm) = shift;
431              
432 0 0       0 croak "missing error-report" unless $parm;
433 0 0       0 croak "invalid error-report" unless (ref($parm) eq "Biblio::ILL::ISO::ErrorReport");
434              
435 0         0 $self->{"error-report"} = $parm;
436              
437 0         0 return;
438             }
439              
440             #---------------------------------------------------------------
441             #
442             #---------------------------------------------------------------
443             =head1
444              
445             =head2 set_note($note)
446              
447             Sets the message's note.
448             Expects a valid Biblio::ILL::ISO::ILLString or a simple text string.
449              
450             $msg->set_note("This is a note");
451              
452             This is an optional field.
453              
454             =cut
455             sub set_note {
456 1     1 1 7 my $self = shift;
457 1         2 my ($parm) = shift;
458              
459 1 50       3 croak "missing note" unless $parm;
460 1 50       4 if (ref($parm) eq "Biblio::ILL::ISO::ILLString") {
461 1         3 $self->{"note"} = $parm;
462             } else {
463 0         0 $self->{"note"} = new Biblio::ILL::ISO::ILLString($parm);
464             }
465              
466 1         8 return;
467             }
468              
469             =head1 RELATED MODULES
470              
471             Biblio::ILL::ISO::ISO
472             Biblio::ILL::ISO::Request
473             Biblio::ILL::ISO::ForwardNotification
474             Biblio::ILL::ISO::Shipped
475             Biblio::ILL::ISO::Answer
476             Biblio::ILL::ISO::ConditionalReply
477             Biblio::ILL::ISO::Cancel
478             Biblio::ILL::ISO::CancelReply
479             Biblio::ILL::ISO::Received
480             Biblio::ILL::ISO::Recall
481             Biblio::ILL::ISO::Returned
482             Biblio::ILL::ISO::CheckedIn
483             Biblio::ILL::ISO::Overdue
484             Biblio::ILL::ISO::Renew
485             Biblio::ILL::ISO::RenewAnswer
486             Biblio::ILL::ISO::Lost
487             Biblio::ILL::ISO::Damaged
488             Biblio::ILL::ISO::Message
489             Biblio::ILL::ISO::StatusQuery
490             Biblio::ILL::ISO::StatusOrErrorReport
491             Biblio::ILL::ISO::Expired
492              
493             =cut
494              
495             =head1 SEE ALSO
496              
497             See the README for system design notes.
498              
499             For more information on Interlibrary Loan standards (ISO 10160/10161),
500             a good place to start is:
501              
502             http://www.nlc-bnc.ca/iso/ill/main.htm
503              
504             =cut
505              
506             =head1 AUTHOR
507              
508             David Christensen,
509              
510             =cut
511              
512              
513             =head1 COPYRIGHT AND LICENSE
514              
515             Copyright 2003 by David Christensen
516              
517             This library is free software; you can redistribute it and/or modify it
518             under the same terms as Perl itself.
519              
520             =cut
521              
522             1;