File Coverage

blib/lib/Biblio/ILL/ISO/SearchType.pm
Criterion Covered Total %
statement 29 53 54.7
branch 9 32 28.1
condition 1 6 16.6
subroutine 7 9 77.7
pod 3 3 100.0
total 49 103 47.5


line stmt bran cond sub pod time code
1             package Biblio::ILL::ISO::SearchType;
2              
3             =head1 NAME
4              
5             Biblio::ILL::ISO::SearchType
6              
7             =cut
8              
9 4     4   737 use Biblio::ILL::ISO::ILLASNtype;
  4         7  
  4         118  
10 4     4   23 use Biblio::ILL::ISO::ILLString;
  4         10  
  4         82  
11 4     4   23 use Biblio::ILL::ISO::ISODate;
  4         7  
  4         179  
12 4     4   24 use Biblio::ILL::ISO::ExpiryFlag;
  4         8  
  4         91  
13              
14 4     4   22 use Carp;
  4         22  
  4         386  
15              
16             =head1 VERSION
17              
18             Version 0.02
19              
20             =cut
21              
22             our $VERSION = '0.02';
23             #---------------------------------------------------------------------------
24             # Mods
25             # 0.02 - 2003.07.17 - new and set were setting dates as ILLStrings, not
26             # ISODates. Fixed.
27             # 0.01 - 2003.07.15 - original version
28             #---------------------------------------------------------------------------
29              
30             =head1 DESCRIPTION
31              
32             Biblio::ILL::ISO::SearchType is a derivation of Biblio::ILL::ISO::ILLASNtype.
33              
34             =head1 USES
35              
36             Biblio::ILL::ISO::ILLString;
37             Biblio::ILL::ISO::ISODate;
38             Biblio::ILL::ISO::ExpiryFlag;
39              
40             =head1 USED IN
41              
42             Biblio::ILL::ISO::Request
43              
44             =cut
45              
46 4     4   2906 BEGIN{@ISA = qw ( Biblio::ILL::ISO::ILLASNtype );} # inherit from ILLASNtype
47              
48             =head1 FROM THE ASN DEFINITION
49            
50             Search-Type ::= SEQUENCE {
51             level-of-service [0] ILL-String OPTIONAL, -- (SIZE (1))
52             need-before-date [1] IMPLICIT ISO-Date OPTIONAL,
53             expiry-flag [2] IMPLICIT ENUMERATED {
54             need-Before-Date (1),
55             other-Date (2),
56             no-Expiry (3)
57             } -- DEFAULT 3,
58             -- value of "need-Before-Date" indicates that
59             -- need-before-date also specifies transaction expiry
60             -- date
61             expiry-date [3] IMPLICIT ISO-Date OPTIONAL
62             -- alternative expiry date can be used only when expiry-flag
63             -- is set to "Other-Date"
64             }
65              
66             =cut
67              
68             =head1 METHODS
69              
70             =cut
71              
72             #---------------------------------------------------------------
73             #
74             #---------------------------------------------------------------
75             =head1
76              
77             =head2 new( $expiry [,$service_level] [,$need_before] [,$expiry_date] )
78              
79             Creates a new SearchType object.
80             Expects an expiry-flag string (text string, valid Biblio::ILL::ISO::ExpiryFlag enumerated value),
81             (optionally) a service-level (text string),
82             (optionally) a need-before-date (Biblio::ILL::ISO::ISODate), and
83             (optionally) an expiry-date (Biblio::ILL::ISO::ISODate).
84              
85             =cut
86             sub new {
87 2     2 1 20 my $class = shift;
88 2         5 my $self = {};
89              
90 2 50       7 if (@_) {
91 2         6 my ($expiry, $servicelevel, $needbefore, $expirydate) = @_;
92              
93 2 50       7 croak "missing expiry-flag" unless ($expiry);
94 2 50       11 if ($servicelevel) {
95 2 50       16 croak "invalid service-level length" unless ((length $servicelevel) == 1);
96             }
97              
98 2         20 $self->{"expiry-flag"} = new Biblio::ILL::ISO::ExpiryFlag($expiry);
99 2 50       14 $self->{"level-of-service"} = new Biblio::ILL::ISO::ILLString($servicelevel) if ($servicelevel);
100 2 100       12 $self->{"need-before-date"} = new Biblio::ILL::ISO::ISODate($needbefore) if ($needbefore);
101 2 100       13 $self->{"expiry-date"} = new Biblio::ILL::ISO::ISODate($expirydate) if ($expirydate);
102             }
103              
104 2   33     15 bless($self, ref($class) || $class);
105 2         7 return ($self);
106             }
107              
108              
109             #---------------------------------------------------------------
110             #
111             #---------------------------------------------------------------
112             =head1
113              
114             =head2 set( $expiry [,$service_level] [,$need_before] [,$expiry_date] )
115              
116             Sets the object's expiry-flag (text string, valid Biblio::ILL::ISO::ExpiryFlag enumerated value),
117             (optionally) service-level (text string),
118             (optionally) need-before-date (Biblio::ILL::ISO::ISODate), and
119             (optionally) expiry-date (Biblio::ILL::ISO::ISODate).
120              
121             =cut
122             sub set {
123 0     0 1   my $self = shift;
124 0           my ($expiry, $servicelevel, $needbefore, $expirydate) = @_;
125              
126 0 0         croak "missing expiry-flag" unless ($expiry);
127 0 0         if ($servicelevel) {
128 0 0         croak "invalid service-level length" unless ((length $servicelevel) == 1);
129             }
130            
131 0           $self->{"expiry-flag"} = new Biblio::ILL::ISO::ExpiryFlag($expiry);
132 0 0         $self->{"level-of-service"} = new Biblio::ILL::ISO::ILLString($servicelevel) if ($servicelevel);
133 0 0         $self->{"need-before-date"} = new Biblio::ILL::ISO::ISODate($needbefore) if ($needbefore);
134 0 0         $self->{"expiry-date"} = new Biblio::ILL::ISO::ISODate($expirydate) if ($expirydate);
135              
136 0           return;
137             }
138              
139             #---------------------------------------------------------------
140             #
141             #---------------------------------------------------------------
142             =head1
143              
144             =head2 from_asn($href)
145              
146             Given a properly formatted hash, builds the object.
147              
148             =cut
149             sub from_asn {
150 0     0 1   my $self = shift;
151 0           my $href = shift;
152              
153 0           foreach my $k (keys %$href) {
154             #print ref($self) . "...$k\n";
155              
156 0 0 0       if ($k =~ /^level-of-service$/) {
    0          
    0          
157 0           $self->{$k} = new Biblio::ILL::ISO::ILLString();
158 0           $self->{$k}->from_asn($href->{$k});
159              
160             } elsif (($k =~ /^need-before-date$/)
161             || ($k =~ /^expiry-date$/)
162             ) {
163 0           print "$k: $href->{$k}\n";
164 0           $self->{$k} = new Biblio::ILL::ISO::ISODate();
165 0           $self->{$k}->from_asn($href->{$k});
166 0           print $self->{$k}->as_string();
167              
168             } elsif ($k =~ /^expiry-flag$/) {
169 0           $self->{$k} = new Biblio::ILL::ISO::ExpiryFlag();
170 0           $self->{$k}->from_asn($href->{$k});
171              
172             } else {
173 0           croak "invalid " . ref($self) . " element: [$k]";
174             }
175              
176             }
177 0           return $self;
178             }
179              
180             =head1 SEE ALSO
181              
182             See the README for system design notes.
183             See the parent class(es) for other available methods.
184              
185             For more information on Interlibrary Loan standards (ISO 10160/10161),
186             a good place to start is:
187              
188             http://www.nlc-bnc.ca/iso/ill/main.htm
189              
190             =cut
191              
192             =head1 AUTHOR
193              
194             David Christensen,
195              
196             =cut
197              
198              
199             =head1 COPYRIGHT AND LICENSE
200              
201             Copyright 2003 by David Christensen
202              
203             This library is free software; you can redistribute it and/or modify it
204             under the same terms as Perl itself.
205              
206             =cut
207             =head1
208              
209             =head2 from_asn($href)
210              
211             Given a properly formatted hash, builds the object.
212              
213             =cut
214              
215             1;