File Coverage

blib/lib/MARC/Descriptions.pm
Criterion Covered Total %
statement 23 25 92.0
branch 6 8 75.0
condition 3 6 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 40 47 85.1


line stmt bran cond sub pod time code
1             package MARC::Descriptions;
2              
3 5     5   8796143 use strict;
  5         12  
  5         232  
4 5     5   28 use Carp qw(croak);
  5         12  
  5         344  
5 5     5   4468 use Clone::Any qw(clone);
  5         9292  
  5         32  
6 5     5   80463 use MARC::Descriptions::Data qw(%MARC_tag_data);
  5         31  
  5         4711  
7              
8             our $VERSION = '0.9';
9              
10             =head1 NAME
11              
12             MARC::Descriptions - MARC metadata looker-upper
13              
14             =head1 SYNOPSIS
15              
16             use MARC::Descriptions
17              
18             my $TD = MARC::Descriptions->new;
19              
20             # hash of all tag data
21             my $href = $TD->get("245");
22              
23             # string description
24             my $s = $TD->get("245", "description");
25              
26             # hash of all subfields
27             my $href = $TD->get("245", "subfield");
28              
29             # hash of subfield 'a'
30             my $href = $TD->get("245", "subfield", "a");
31              
32             # description of subfield 'a'
33             my $s = $TD->get("245", "subfield", "a", "description");
34              
35             =head1 DESCRIPTION
36              
37             MARC::Description allows you to get either a string of information about a particular
38             bit of a MARC record (eg: the description of the 245 tag, or the flags associated
39             with tag 245 subfield \$a), or a hash of (hashes of) strings of information about a
40             particular subset of a MARC record (eg: all of the 2nd indicators for tag 245, or
41             all of the subfields for tag 245, or even a complete breakdown of tag 245).
42              
43             =cut
44              
45             =head1 CONSTRUCTOR
46              
47             =head2 new()
48              
49             Creates the MARC::Descriptions object. You only ever need one of these; all
50             of the fun stuff is done in get().
51              
52             =cut
53             sub new {
54 3     3 1 456 my $class = shift;
55 3         7 my $self = {};
56              
57 3         9 bless $self, $class;
58 3         8 return $self;
59             } # new()
60              
61             =head1 METHODS
62              
63             =head2 get( $tag [, $parm1 [, $parm2 [, $parm3]]] )
64              
65             Returns information about the MARC structure.
66              
67             tag is the MARC tag
68             eg: get("010")
69             With no other parameters, this returns a hash of all information
70             about that tag.
71              
72             parm1 can be one of:
73             "description","shortname", or "flags" (eg: get("245","description")),
74             in which case a string is returned with that information,
75             or
76             "ind1","ind2","subfield" (eg: get("245","subfield")),
77             in which case parm2 will be the indicator/subfield that you're
78             interested in, and get() will return a hash of the information
79             about all possible indicators or subfields.
80              
81             If both parm1 and parm2 are specified, then parm3 can also be specified
82             to have get() return a string containing information about that particular
83             indicator/subfield. (eg: get("245","subfield","a"))
84              
85             =cut
86             sub get {
87 13     13 1 4324 my $self = shift;
88 13         31 my ($tag, @options) = @_;
89              
90 13 50       30 if( @options ) {
91 13         16 $_ = $options[ 0 ];
92              
93 13 100       96 return $MARC_tag_data{ $tag }{ $1 } if /^(description|flags|shortname)$/i;
94 8 100 66     142 return clone( $MARC_tag_data{ $tag }{ $1 } ) if /^(ind[12]|subfield)/i and @options == 1;
95 5 50 33     74 return clone( $MARC_tag_data{ $tag }{ $1 }{ $options[ 1 ] }{$options[ 2 ] } ) if /^(ind[12]|subfield)/i and @options == 3;
96              
97 0           return;
98              
99             }
100              
101             # return everything for this tag
102 0           return clone( $MARC_tag_data{ $tag } );
103             }
104              
105             =head1 THE HASH
106              
107             If you've asked get() to return a hash, it will look like this (or
108             a subset of this) - the example is for get("010"):
109              
110             {
111             flags => "",
112             shortname => "LCCN",
113             description => "Library of Congress Control Number",
114             ind1 => {
115             "#" => {
116             flags => "",
117             description => "Unused",
118             },
119             },
120             ind2 => {
121             "#" => {
122             flags => "",
123             description => "Blank",
124             },
125             },
126             subfield => {
127             "a" => {
128             flags => "",
129             description => "LC control number",
130             },
131             "b" => {
132             flags => "aR",
133             description => "National Union Catalog of Manuscript Collections Control Number",
134             },
135             "z" => {
136             flags => "R",
137             description => "Canceled/invalid LC control number",
138             },
139             },
140             }
141              
142             =cut
143              
144             =head1 SEE ALSO
145              
146             =over 4
147              
148             =item * perl4lib (L)
149              
150             A mailing list devoted to the use of Perl in libraries.
151              
152             =item * Library Of Congress MARC pages (L)
153              
154             The definitive source for all things MARC.
155              
156              
157             =item * I (L)
158              
159             Online version of the free booklet. An excellent overview of the MARC format. Essential.
160              
161              
162             =item * Tag Of The Month (L)
163              
164             Follett Software Company's
165             (L) monthly discussion of various MARC tags.
166              
167              
168             =item * Cataloguer's Reference Shelf (L)
169              
170             The Library Corporation's (L:)
171             free online resource for cataloguers.
172              
173             =back
174              
175             =head1 AUTHOR
176              
177             David Christensen,
178              
179             =cut
180              
181             =head1 COPYRIGHT AND LICENSE
182              
183             Copyright 2003 by David Christensen
184              
185             This library is free software; you can redistribute it and/or modify it
186             under the same terms as Perl itself.
187              
188             =cut
189              
190             1;