File Coverage

blib/lib/Biblio/ILL/GS.pm
Criterion Covered Total %
statement 56 61 91.8
branch 14 26 53.8
condition 1 3 33.3
subroutine 7 7 100.0
pod 3 3 100.0
total 81 100 81.0


line stmt bran cond sub pod time code
1             package Biblio::ILL::GS;
2              
3             =head1 NAME
4              
5             Biblio::ILL::GS - Interlibrary Loan Generic Script (GS)
6              
7             =cut
8              
9 3     3   110171 use strict;
  3         8  
  3         108  
10 3     3   16 use warnings;
  3         5  
  3         99  
11 3     3   15 use Carp qw( carp croak );
  3         12  
  3         2774  
12              
13             =head1 VERSION
14              
15             Version 0.05
16              
17             =cut
18             our $VERSION = '0.05';
19              
20             my @validFields = (
21             'LSB', # Library Symbol, Borrower
22             'LSP', # Lending library symbol
23             'A#C', # Account number
24             'P/U', # Patron name
25             'N/R', # Need-before date
26             'ADR', # Address or delivery service (multiple lines)
27             'SER', # Service
28             'AUT', # Author
29             'TIT', # Title
30             'P/L', # Place of publication
31             'P/M', # Publisher
32             'EDN', # Edition
33             'DAT', # Publication date
34             'LCN', # Local contron number
35             'SBN', # ISBN
36             'NUM', # Other numbers/letters (multiple lines)
37             '#AD', # Other
38             'SRC', # Source of your information
39             'REM', # Remarks
40             );
41              
42             =head1 SYNOPSIS
43              
44             use Biblio::ILL::GS;
45             my $gs = new Biblio::ILL::GS;
46              
47             $gs->set("LSB", "MWPL" );
48             $gs->set("LSP", "BVAS" );
49             $gs->set("P/U", "Christensen, David" );
50              
51             $gs->set( "ADR",
52             "Public Library Services",
53             "Interlibrary Loan Department",
54             "1525 First Street South",
55             "Brandon, MB R7A 7A1"
56             );
57              
58             $gs->set("SER", "LOAN" );
59             $gs->set("AUT", "Wall, Larry" );
60             $gs->set("TIT", "Programming Perl" );
61             $gs->set("P/L", "Cambridge, Mass." );
62             $gs->set("P/M", "O'Reilly" );
63             $gs->set("EDN", "2nd Ed." );
64             $gs->set("DAT", "2000" );
65             $gs->set("SBN", "0596000278" );
66             $gs->set("SRC", "TEST SCRIPT" );
67             $gs->set("REM", "This is a comment.", "And another comment." );
68              
69             # ouptut our string
70             print $gs->as_string();
71              
72              
73             =head1 DESCRIPTION
74              
75             Biblio::ILL::GS is a little bit of glue....
76              
77             Our library web site (http://maplin.gov.mb.ca) uses Perl (of course)
78             and Z39.50 to enable our libraries to search for and request items
79             amongst themselves (and, for that matter, to/from the world at large).
80              
81             The basic procedue is: find the item, parse the resulting record,
82             build a human-readable email out of it, and send it - all automagically.
83              
84             One of our libraries has moved to an interlibrary-loan management system,
85             and would rather not have to re-key this data as it arrives. Their
86             system, however, does have the ability to process requests in the
87             Interlibrary Loan Generic Script (GS) format.
88              
89             Biblio::ILL::GS simply lets you build a GS format message.
90              
91             =head1 METHODS
92              
93             =head2 new()
94              
95             Create the Biblio::ILL::GS object.
96              
97             my $gs = new Biblio::ILL::GS;
98              
99             =cut
100              
101             sub new {
102 2     2 1 26 my $class = shift;
103 2   33     20 return( bless { }, ref($class) || $class );
104             }
105              
106              
107             =head2 set()
108              
109             Set a field in the object. Fields can accept multiple values, which you pass in
110             a list context. If you do not pass in a valid field name you will
111             get a fatal error. Valid fields names include:
112             LSB, LSP A#C P/U N/R ADR SER AUT TIT P/L P/M EDN DAT LCN SBN NUM #AD SRC REM
113              
114             my $gs = new Biblio::ILL::GS;
115             $gs->set( 'TIT', 'Huckleberry Finn' );
116             $gs->set( 'REM', 'This is a comment.', 'This is another comment' );
117              
118             =cut
119              
120             sub set {
121 28     28 1 4470 my ($self,$fieldname,@ary) = @_;
122 28 50       509 if ( ! grep /$fieldname/, @validFields ) {
123 0         0 croak( "invalid field $fieldname" );
124             }
125 28         125 $self->{$fieldname} = [ @ary ];
126             }
127              
128              
129             =head2 as_string()
130              
131             Returns the GS message as a string, or undef if the minimum data is not
132             present (LSB, LSP, ADR, SER, AUT, and TIT).
133              
134             =cut
135              
136             sub as_string {
137              
138 8     8 1 6980 my $self = shift;
139 8         12 my $GS;
140              
141             # verify that we have the (minimum) data we need
142              
143 8         20 foreach ( qw( LSB LSP ADR SER AUT TIT ) ) {
144 33 100       115 if ( ! defined( $self->{ $_ } ) ) {
145 6         1039 croak( "missing mandatory field: $_" );
146             }
147             }
148              
149             # I think this is the real start of the GS msg....
150 2         8 $GS .= "\t\t\tILL REQUEST/DEMANDE DE PEB\n\n";
151              
152             # why do only some of these check for existence
153             # - some are mandatory, some optional (but handy)
154 2         6 $GS .= "LSB:" . _stringify( @{ $self->{"LSB"} });
  2         12  
155 2         6 $GS .= "LSP:" . _stringify( @{ $self->{"LSP"} });
  2         12  
156 2 50       13 $GS .= "A#C:" . _stringify( @{ $self->{"A#C"} }) if ($self->{"A#C"});
  0         0  
157 2 50       9 $GS .= "P/U:" . _stringify( @{ $self->{"P/U"} }) if ($self->{"P/U"});
  2         9  
158 2 50       10 $GS .= "N/R:" . _stringify( @{ $self->{"N/R"} }) if ($self->{"N/R"});
  0         0  
159 2         4 $GS .= "ADR:" . _stringify( @{ $self->{"ADR"} });
  2         8  
160 2         6 $GS .= "SER:" . _stringify( @{ $self->{"SER"} });
  2         8  
161 2         17 $GS .= "AUT:" . _stringify( @{ $self->{"AUT"} });
  2         76  
162 2         5 $GS .= "TIT:" . _stringify( @{ $self->{"TIT"} });
  2         8  
163 2 50       10 $GS .= "P/L:" . _stringify( @{ $self->{"P/L"} }) if ($self->{"P/L"});
  2         7  
164 2 50       11 $GS .= "P/M:" . _stringify( @{ $self->{"P/M"} }) if ($self->{"P/M"});
  2         6  
165 2 50       18 $GS .= "EDN:" . _stringify( @{ $self->{"EDN"} }) if ($self->{"N/R"});
  0         0  
166 2 50       10 $GS .= "DAT:" . _stringify( @{ $self->{"DAT"} }) if ($self->{"DAT"});
  2         7  
167 2 50       10 $GS .= "LCN:" . _stringify( @{ $self->{"LCN"} }) if ($self->{"LCN"});
  0         0  
168 2 50       9 $GS .= "SBN:" . _stringify( @{ $self->{"SBN"} }) if ($self->{"SBN"});
  2         7  
169 2 50       10 $GS .= "SRC:" . _stringify( @{ $self->{"SRC"} }) if ($self->{"SRC"});
  2         6  
170 2 50       13 $GS .= "REM:" . _stringify( @{ $self->{"REM"} }) if ($self->{"REM"});
  2         8  
171              
172 2         47 return( $GS );
173              
174             }
175              
176             sub _stringify {
177 26     26   70 my (@v) = @_;
178 26         30 my $s;
179 26         40 foreach my $elem (@v) {
180 34         88 $s .= "\t" . $elem . "\n";
181             }
182 26         109 return( $s );
183             }
184              
185             1;
186              
187              
188             __END__