File Coverage

blib/lib/Net/OAI/ResumptionToken.pm
Criterion Covered Total %
statement 52 57 91.2
branch 24 32 75.0
condition 1 3 33.3
subroutine 12 12 100.0
pod 9 9 100.0
total 98 113 86.7


line stmt bran cond sub pod time code
1             package Net::OAI::ResumptionToken;
2              
3 16     16   85 use strict;
  16         34  
  16         490  
4 16     16   81 use base qw( XML::SAX::Base );
  16         34  
  16         1098  
5 16     16   82 use Carp qw( carp );
  16         29  
  16         11761  
6              
7              
8             =head1 NAME
9              
10             Net::OAI::ResumptionToken - An OAI-PMH resumption token.
11              
12             =head1 SYNOPSIS
13              
14             =head1 DESCRIPTION
15              
16             This SAX filter records resumption token elements.
17              
18             =head1 METHODS
19              
20             =head2 new()
21              
22             =cut
23              
24             sub new {
25 17     17 1 619 my ( $class, %opts ) = @_;
26 17   33     205 my $self = bless \%opts, ref( $class ) || $class;
27 17         116 $self->{ _insideResumptionToken } = 0;
28 17         109 $self->{ token } = $self->{ expirationDate } = $self->{ completeListSize } = $self->{ cursor } = undef;
29 17         86 return( $self );
30             }
31              
32             =head2 token()
33              
34             (Sets and) returns the contents of the resumptionToken element.
35              
36             All methods return C if no token was encountered.
37              
38             =cut
39              
40             sub token {
41 24     24 1 2128 my ( $self, $token ) = @_;
42 24 50       92 if ( $token ) { $self->{ token } = $token; }
  0         0  
43 24         161 return( $self->{ resumptionTokenText } );
44             }
45              
46             =head2 expirationDate()
47              
48             =cut
49              
50             sub expirationDate {
51 5     5 1 332 my ( $self, $date ) = @_;
52 5 100       22 if ( $date ) { $self->{ expirationDate } = $date; }
  1         3  
53 5         19 return( $self->{ expirationDate } );
54             }
55              
56             =head2 completeListSize()
57              
58             =cut
59              
60             sub completeListSize {
61 5     5 1 1091 my ( $self, $size ) = @_;
62 5 100       23 if ( $size ) { $self->{ completeListSize } = $size; }
  1         2  
63 5         20 return( $self->{ completeListSize } );
64             }
65              
66             =head2 cursor()
67              
68             =cut
69              
70             sub cursor {
71 5     5 1 1107 my ( $self, $cursor ) = @_;
72 5 100       23 if ( $cursor ) { $self->{ cursor } = $cursor; }
  1         3  
73 5         452 return( $self->{ cursor } );
74             }
75              
76              
77             =head1 AUTHORS
78              
79             Ed Summers
80              
81             =cut
82              
83             ## internal stuff
84              
85             ## all children of Net::OAI::Base should call this to make sure
86             ## certain object properties are set
87             sub start_prefix_mapping {
88 4400     4400 1 28682 my ($self, $mapping) = @_;
89 4400 50       9122 die "rT: self not defined" unless defined $self;
90 4400 50       11084 return $self->SUPER::start_prefix_mapping( $mapping ) if $self->get_handler();
91 0         0 die "rT: start_prefix_mapping @{[$mapping]} w/o Handler";
  0         0  
92             }
93              
94              
95             sub start_element {
96 66594     66594 1 410615 my ( $self, $element ) = @_;
97 66594 100       208767 return $self->SUPER::start_element( $element ) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;
98              
99 32217 100       91617 if ( $element->{ LocalName } eq 'resumptionToken' ) {
    50          
100 12         29 my $attr = $element->{ Attributes };
101 12 50       45 $self->{ expirationDate } = $attr->{ '{}expirationDate' }{ Value } if $attr->{ '{}expirationDate' };
102 12 50       70 $self->{ completeListSize } = $attr->{ '{}completeListSize' }{ Value } if $attr->{ '{}completeListSize' };
103 12 50       140 $self->{ cursor } = $attr->{ '{}cursor' }{ Value } if $attr->{ '{}cursor' };
104 12         48 $self->{ resumptionTokenText } = "";
105 12         72 $self->{ _insideResumptionToken } = 1;
106             } elsif ( $self->{ _insideResumptionToken } ) {
107 0         0 carp "start of unhandled subelement ".$element->{ Name }." within resumptionToken";
108             } else {
109 32205         78912 $self->SUPER::start_element( $element );
110             }
111             }
112              
113             sub end_element {
114 66594     66594 1 400826 my ( $self, $element ) = @_;
115 66594 100       205385 return $self->SUPER::end_element( $element ) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;
116              
117 32217 100       88212 if ( $element->{ LocalName } eq 'resumptionToken' ) {
    50          
118 12         45 Net::OAI::Harvester::debug( "caught resumption token" );
119 12         44 $self->{ _insideResumptionToken } = 0;
120             } elsif ( $self->{ _insideResumptionToken } ) {
121 0         0 carp "end of unhandled subelement ".$element->{ Name }." within resumptionToken";
122             } else {
123 32205         76506 $self->SUPER::end_element( $element );
124             }
125             }
126              
127             sub characters {
128 140636     140636 1 820433 my ( $self, $characters ) = @_;
129              
130 140636 100       283381 if ( $self->{ _insideResumptionToken } ) {
131 12         129 $self->{ resumptionTokenText } .= $characters->{ Data };
132             } else {
133 140624         329312 $self->SUPER::characters( $characters );
134             }
135             }
136              
137             1;
138