File Coverage

blib/lib/Biblio/ILL/ISO/RenewAnswer.pm
Criterion Covered Total %
statement 58 94 61.7
branch 14 46 30.4
condition 1 6 16.6
subroutine 12 15 80.0
pod 12 12 100.0
total 97 173 56.0


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