| 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 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use Carp qw( carp croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Version 0.05 | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||
| 18 | 3 | our $VERSION = '0.05'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 3 | 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 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||
| 102 | 2 | my $class = shift; | |||||||||||||||||||
| 103 | 2 | ▶ | return( bless { }, ref($class) || $class ); | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $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 | 28 | ▶ | sub set { | ||||||||||||||||||
|
Subroutine
set: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 121 | 28 | my ($self,$fieldname,@ary) = @_; | |||||||||||||||||||
| 122 | 28 | ▶ | if ( ! grep /$fieldname/, @validFields ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | 0 | croak( "invalid field $fieldname" ); | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | 28 | $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 | 8 | ▶ | sub as_string { | ||||||||||||||||||
|
Subroutine
as_string: called CC=14 SCAR=28.0
Pod
documented
| |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 8 | my $self = shift; | |||||||||||||||||||
| 139 | 8 | my $GS; | |||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | # verify that we have the (minimum) data we need | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 8 | foreach ( qw( LSB LSP ADR SER AUT TIT ) ) { | |||||||||||||||||||
| 144 | 33 | ▶ | if ( ! defined( $self->{ $_ } ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 145 | 6 | croak( "missing mandatory field: $_" ); | |||||||||||||||||||
| 146 | } | ||||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | # I think this is the real start of the GS msg.... | ||||||||||||||||||||
| 150 | 2 | $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 | $GS .= "LSB:" . _stringify( @{ $self->{"LSB"} }); | |||||||||||||||||||
| 155 | 2 | $GS .= "LSP:" . _stringify( @{ $self->{"LSP"} }); | |||||||||||||||||||
| 156 | 0 | ▶ | $GS .= "A#C:" . _stringify( @{ $self->{"A#C"} }) if ($self->{"A#C"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | 2 | ▶ | $GS .= "P/U:" . _stringify( @{ $self->{"P/U"} }) if ($self->{"P/U"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 0 | ▶ | $GS .= "N/R:" . _stringify( @{ $self->{"N/R"} }) if ($self->{"N/R"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | 2 | $GS .= "ADR:" . _stringify( @{ $self->{"ADR"} }); | |||||||||||||||||||
| 160 | 2 | $GS .= "SER:" . _stringify( @{ $self->{"SER"} }); | |||||||||||||||||||
| 161 | 2 | $GS .= "AUT:" . _stringify( @{ $self->{"AUT"} }); | |||||||||||||||||||
| 162 | 2 | $GS .= "TIT:" . _stringify( @{ $self->{"TIT"} }); | |||||||||||||||||||
| 163 | 2 | ▶ | $GS .= "P/L:" . _stringify( @{ $self->{"P/L"} }) if ($self->{"P/L"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | 2 | ▶ | $GS .= "P/M:" . _stringify( @{ $self->{"P/M"} }) if ($self->{"P/M"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 165 | 0 | ▶ | $GS .= "EDN:" . _stringify( @{ $self->{"EDN"} }) if ($self->{"N/R"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 166 | 2 | ▶ | $GS .= "DAT:" . _stringify( @{ $self->{"DAT"} }) if ($self->{"DAT"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 167 | 0 | ▶ | $GS .= "LCN:" . _stringify( @{ $self->{"LCN"} }) if ($self->{"LCN"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 168 | 2 | ▶ | $GS .= "SBN:" . _stringify( @{ $self->{"SBN"} }) if ($self->{"SBN"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 169 | 2 | ▶ | $GS .= "SRC:" . _stringify( @{ $self->{"SRC"} }) if ($self->{"SRC"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 170 | 2 | ▶ | $GS .= "REM:" . _stringify( @{ $self->{"REM"} }) if ($self->{"REM"}); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | 2 | return( $GS ); | |||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | } | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | 26 | ▶ | sub _stringify { | ||||||||||||||||||
|
Subroutine
_stringify: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 177 | 26 | my (@v) = @_; | |||||||||||||||||||
| 178 | 26 | my $s; | |||||||||||||||||||
| 179 | 26 | foreach my $elem (@v) { | |||||||||||||||||||
| 180 | 34 | $s .= "\t" . $elem . "\n"; | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | 26 | return( $s ); | |||||||||||||||||||
| 183 | } | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 3 | 1; | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | __END__ | ||||||||||||||||||||