File Coverage

blib/lib/Net/OAI/Identify.pm
Criterion Covered Total %
statement 59 65 90.7
branch 17 18 94.4
condition 1 3 33.3
subroutine 13 14 92.8
pod 12 12 100.0
total 102 112 91.0


line stmt bran cond sub pod time code
1             package Net::OAI::Identify;
2              
3 16     16   81 use strict;
  16         31  
  16         451  
4 16     16   79 use base qw( XML::SAX::Base Net::OAI::Base );
  16         32  
  16         9632  
5              
6             =head1 NAME
7              
8             Net::OAI::Identify - Results of the Identify OAI-PMH verb.
9              
10             =head1 SYNOPSIS
11              
12             =head1 DESCRIPTION
13              
14             =head1 METHODS
15              
16             =head2 new()
17              
18             =cut
19              
20             sub new {
21 6     6 1 29 my ( $class, %opts ) = @_;
22 6   33     49 my $self = bless \%opts, ref( $class ) || $class;
23 6         44 $self->{ repositoryName } = '';
24 6         22 $self->{ baseUrl } = '';
25 6         20 $self->{ protocolVersion } = '';
26 6         19 $self->{ earliestDatestamp } = '';
27 6         19 $self->{ deletedRecord } = '';
28 6         19 $self->{ granularity } = '';
29 6         24 $self->{ adminEmail } = '';
30 6         20 $self->{ adminEmails } = [];
31 6         18 $self->{ compression } = '';
32 6         18 $self->{ compressions } = [];
33 6         19 $self->{ _insideDescription } = 0;
34 6         34 return( $self );
35             }
36              
37             =head2 repositoryName()
38              
39             Returns the name of the repostiory.
40              
41             =cut
42              
43             sub repositoryName {
44 1     1 1 3 my $self = shift;
45 1         7 return( $self->{ repositoryName } );
46             }
47              
48             =head2 baseURL()
49              
50             Returns the base URL used by the repository.
51              
52             =cut
53              
54             sub baseURL {
55 0     0 1 0 my $self = shift;
56 0         0 return( $self->{ baseURL } );
57             }
58              
59             =head2 protocolVersion()
60              
61             Returns the version of the OAI-PMH used by the repository.
62              
63             =cut
64              
65             sub protocolVersion {
66 1     1 1 4 my $self = shift;
67 1         6 return( $self->{ protocolVersion } );
68             }
69              
70             =head2 earliestDatestamp()
71              
72             Returns the earlies datestamp for records available in the repository.
73              
74             =cut
75              
76             sub earliestDatestamp {
77 1     1 1 3 my $self = shift;
78 1         15 return( $self->{ earliestDatestamp } );
79             }
80              
81             =head2 deletedRecord()
82              
83             Indicates the way the repository works with deleted records. Should
84             return I, I or I.
85              
86             =cut
87              
88             sub deletedRecord {
89 1     1 1 3 my $self = shift;
90 1         8 return( $self->{ deletedRecord } );
91             }
92              
93             =head2 granularity()
94              
95             Returns the granularity used by the repository.
96              
97             =cut
98              
99             sub granularity {
100 1     1 1 3 my $self = shift;
101 1         6 return( $self->{ granularity } );
102             }
103              
104             =head2 adminEmail()
105              
106             Returns the administrative email address for the repository. Since the
107             adminEmail elelemnt is allowed to repeat you will get all the emails (if more
108             than one are specified) by using adminEmail in a list context.
109              
110             $email = $identity->adminEmail();
111             @emails = $identity->adminEmails();
112              
113             =cut
114              
115             sub adminEmail {
116 2     2 1 6 my $self = shift;
117 2 100       7 if ( wantarray() ) { return( @{ $self->{ adminEmails } } ); }
  1         3  
  1         5  
118 1         4 return( $self->{ adminEmails }[ 0 ] );
119             }
120              
121             =head2 compression()
122              
123             Returns the types of compression that the archive supports. Since the
124             compression element may repeat you may get all the values by using
125             compression() in a list context.
126              
127             $compression = $identity->compression();
128             @compressions = $identity->compressions();
129              
130             =cut
131              
132             sub compression {
133 2     2 1 856 my $self = shift;
134 2 100       8 if ( wantarray() ) { return( @{ $self->{ compressions } } ); }
  1         2  
  1         5  
135 1         4 return( $self->{ compressions }[ 0 ] );
136             }
137              
138             =head1 TODO
139              
140             Support for the various C containers.
141              
142             =cut
143              
144             ## SAX Handlers
145              
146             sub start_element {
147 33     33 1 208 my ( $self, $element ) = @_;
148 33 100       114 return $self->SUPER::start_element($element) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI; # should be error?
149              
150 14         15 push( @{ $self->{ tagStack } }, $element->{ LocalName } );
  14         39  
151 14 100       80 $self->{ _insideDescription } = 1 if $element->{ LocalName } eq 'description';
152             }
153              
154             sub end_element {
155 33     33 1 209 my ( $self, $element ) = @_;
156 33 100       121 return $self->SUPER::end_element($element) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI; # should be error?
157              
158             ## store and reset elements that can have multiple values
159 14 100       41 if ( $element->{ LocalName } eq 'adminEmail' ) {
    50          
160 3         10 Net::OAI::Harvester::debug( "got adminEmail in Identify" );
161 3         4 push( @{ $self->{ adminEmails } }, $self->{ adminEmail } );
  3         11  
162 3         8 $self->{ adminEmail } = '';
163             }
164             elsif ( $element->{ LocalName } eq 'compression' ) {
165 0         0 Net::OAI::Harvester::debug( "got compression in Identify" );
166 0         0 push( @{ $self->{ compressions } }, $self->{ compression } );
  0         0  
167 0         0 $self->{ compression } = '';
168             }
169 14         17 pop( @{ $self->{ tagStack } } );
  14         29  
170 14 100       67 $self->{ _insideDescription } = 0 if $element->{ LocalName } eq 'description';
171             }
172              
173             sub characters {
174 71     71 1 428 my ( $self, $characters ) = @_;
175              
176 71 100       146 if ( $self->{ _insideDescription } ) {
177 39         111 return $self->SUPER::characters( $characters );
178             } else {
179             $self->{ $self->{ tagStack }[-1] } .= $characters->{ Data }
180 32         164 }
181             }
182              
183             1;
184