lib/HTTP/OAI/SAXHandler.pm

filter: Statementstmt 55.9% 66 / 118 Branchbran 57.1% 8 / 14 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 34.1% 14 / 41 Podpod 70.8% 17 / 24 totaltotal 51.4% 107 / 208 CC 11 SCAR 10.3
CC
11
Cov
55%
g_start_element
12.0
g_data_element
6.0
g_end_element
6.0
CRAP 2.8
« lib/HTTP/OAI/Metadata/OAI_Identifier.pm ↑ Summary lib/HTTP/OAI/ListRecords.pm »
1 package HTTP::OAI::SAXHandler;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Data::Dumper; # debugging for here
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 our $VERSION = '4.13';
11  
12 11 @ISA = qw( Exporter XML::SAX::Base );
13  
14 11 @EXPORT_OK = qw( g_start_document g_start_element g_end_element g_data_element );
15 11 %EXPORT_TAGS = (SAX=>[qw( g_start_document g_start_element g_end_element g_data_element )]);
16  
17 =pod
18  
19 =head1 NAME
20  
21 HTTP::OAI::SAXHandler - SAX2 utility filter
22  
23 =head1 DESCRIPTION
24  
25 This module provides utility methods for SAX2, including collapsing multiple "characters" events into a single event.
26  
27 This module exports methods for generating SAX2 events with Namespace support. This *isn't* a fully-fledged SAX2 generator!
28  
29 =over 4
30  
31 =item $h = HTTP::OAI::SAXHandler->new()
32  
33 Class constructor.
34  
35 =cut
36  
37 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
38 2 my ($class,%args) = @_;
39 2 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
40 2 my $self = $class->SUPER::new(%args);
41 2 $self->{Depth} = 0;
42 2 $self;
43 }
44  
45 0 ▶sub g_start_document {
Subroutine g_start_document: not called CC=1 SCAR=6.9
Pod undocumented
46 0 my ($handler) = @_;
47 0 $handler->start_document();
48 0 $handler->start_prefix_mapping({
49 'Prefix'=>'xsi',
50 'NamespaceURI'=>'http://www.w3.org/2001/XMLSchema-instance'
51 });
52 0 $handler->start_prefix_mapping({
53 'Prefix'=>'',
54 'NamespaceURI'=>'http://www.openarchives.org/OAI/2.0/'
55 });
56 }
57  
58 0 ▶sub g_data_element {
Subroutine g_data_element: not called CC=2 SCAR=17.9
Pod undocumented
59 0 my ($handler,$uri,$qName,$attr,$value) = @_;
60 0 g_start_element($handler,$uri,$qName,$attr);
61 0 ▶ if( ref($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 0 0 0
62 0 $value->set_handler($handler);
63 0 $value->generate;
64 } else {
65 0 $handler->characters({'Data'=>$value});
66 }
67 0 g_end_element($handler,$uri,$qName);
68 }
69  
70 0 ▶sub g_start_element {
Subroutine g_start_element: not called CC=3 SCAR=24.8
Pod undocumented
71 0 my ($handler,$uri,$qName,$attr) = @_;
72 0 ▶ $attr ||= {};
Condition0%0/2
$attr ||= {}
l!l
00
MC/DC0%0/1
$attr ||= {}
$attr
Truth table0%0/2
A
A= $attr
Aresult
11
00
73 0 my ($prefix,$localName) = split /:/, $qName;
74 0 ▶ unless(defined($localName)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $localName) 0 0 0
75 0 $localName = $prefix;
76 0 $prefix = '';
77 }
78 $handler->start_element({
79 0 'NamespaceURI'=>$uri,
80 'Name'=>$qName,
81 'Prefix'=>$prefix,
82 'LocalName'=>$localName,
83 'Attributes'=>$attr
84 });
85 }
86  
87 0 ▶sub g_end_element {
Subroutine g_end_element: not called CC=2 SCAR=17.9
Pod undocumented
88 0 my ($handler,$uri,$qName) = @_;
89 0 my ($prefix,$localName) = split /:/, $qName;
90 0 ▶ unless(defined($localName)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $localName) 0 0 0
91 0 $localName = $prefix;
92 0 $prefix = '';
93 }
94 $handler->end_element({
95 0 'NamespaceURI'=>$uri,
96 'Name'=>$qName,
97 'Prefix'=>$prefix,
98 'LocalName'=>$localName,
99 });
100 }
101  
102 0 ▶sub current_state {
Subroutine current_state: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my $self = shift;
104 0 return $self->{State}->[$#{$self->{State}}];
105 }
106  
107 0 ▶sub current_element {
Subroutine current_element: not called CC=1 SCAR=6.9
Pod undocumented
108 0 my $self = shift;
109 0 return $self->{Elem}->[$#{$self->{Elem}}];
110 }
111  
112 2 ▶sub start_document {
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
113 2 HTTP::OAI::Debug::sax( Dumper($_[1]) );
114 2 $_[0]->SUPER::start_document();
115 }
116  
117 2 ▶sub end_document {
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
118 2 $_[0]->SUPER::end_document();
119 2 HTTP::OAI::Debug::sax( Dumper($_[1]) );
120 }
121  
122 # Char data is rolled together by this module
123 17 ▶sub characters {
Subroutine characters: called CC=1 SCAR=0.0
Pod documented
124 17 my ($self,$hash) = @_;
125 17 $self->{Text} .= $hash->{Data};
126 # characters are traced in {start,end}_element
127 #HTTP::OAI::Debug::sax( "'" . substr($hash->{Data},0,40) . "'" );
128 }
129  
130 15 ▶sub start_element {
Subroutine start_element: called CC=2 SCAR=6.9
Pod documented
131 15 my ($self,$hash) = @_;
132 15 push @{$self->{Attributes}}, $hash->{Attributes};
133  
134 # Call characters with the joined character data
135 15 ▶ if( defined($self->{Text}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Text"}) 4 11 15
136 {
137 4 HTTP::OAI::Debug::sax( "'".substr($self->{Text},0,40) . "'" );
138 4 $self->SUPER::characters({Data=>$self->{Text}});
139 4 $self->{Text} = undef;
140 }
141  
142 15 $hash->{State} = $self;
143 15 $hash->{Depth} = ++$self->{Depth};
144 15 HTTP::OAI::Debug::sax( (" " x $hash->{Depth}) . '<'.$hash->{Name}.'>' );
145 15 $self->SUPER::start_element($hash);
146 }
147  
148 15 ▶sub end_element {
Subroutine end_element: called CC=4 SCAR=13.9
Pod documented
149 15 my ($self,$hash) = @_;
150  
151 # Call characters with the joined character data
152 15 $hash->{Text} = $self->{Text};
153 15 ▶ if( defined($self->{Text}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Text"}) 13 2 15
154 {
155 # Trailing whitespace causes problems
156 13 ▶ if( $self->{Text} =~ /\S/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Text"} =~ /\S/) 12 1 13
157 {
158 12 HTTP::OAI::Debug::sax( "'".substr($self->{Text},0,40) . "'" );
159 12 $self->SUPER::characters({Data=>$self->{Text}});
160 }
161 13 $self->{Text} = undef;
162 }
163  
164 15 ▶ $hash->{Attributes} = pop @{$self->{Attributes}} || {};
Condition50%1/2
pop @{$$self{'Attributes'};} || {}
l!l
150
MC/DC0%0/1
pop @{$$self{'Attributes'};} || {}
pop @{$$self{'Attributes'};}
Truth table50%1/2
A
A= pop @{$$self{'Attributes'};}
Aresult
11
00
165 15 $hash->{State} = $self;
166 15 $hash->{Depth} = $self->{Depth}--;
167 15 HTTP::OAI::Debug::sax( (" " x $hash->{Depth}) . ' <'.$hash->{Name}.'>' );
168 15 $self->SUPER::end_element($hash);
169 }
170  
171 0 ▶sub entity_reference {
Subroutine entity_reference: not called CC=1 SCAR=6.9
Pod documented
172 0 my ($self,$hash) = @_;
173 0 HTTP::OAI::Debug::sax( $hash->{Name} );
174 }
175  
176 0 ▶sub start_cdata {
Subroutine start_cdata: not called CC=1 SCAR=6.9
Pod documented
177 0 HTTP::OAI::Debug::sax();
178 }
179  
180 0 ▶sub end_cdata {
Subroutine end_cdata: not called CC=1 SCAR=6.9
Pod documented
181 0 HTTP::OAI::Debug::sax();
182 }
183  
184 0 ▶sub comment {
Subroutine comment: not called CC=1 SCAR=6.9
Pod documented
185 0 HTTP::OAI::Debug::sax( $_[1]->{Data} );
186 }
187  
188 0 ▶sub doctype_decl {
Subroutine doctype_decl: not called CC=1 SCAR=6.9
Pod documented
189 # {SystemId,PublicId,Internal}
190 0 HTTP::OAI::Debug::sax( $_[1]->{Name} );
191 }
192  
193 0 ▶sub attlist_decl {
Subroutine attlist_decl: not called CC=1 SCAR=6.9
Pod documented
194 # {ElementName,AttributeName,Type,Default,Fixed}
195 0 HTTP::OAI::Debug::sax( $_[1]->{ElementName} );
196 }
197  
198 2 ▶sub xml_decl {
Subroutine xml_decl: called CC=2 SCAR=6.9
Pod documented
199 # {Version,Encoding,Standalone}
200 2 ▶HTTP::OAI::Debug::sax( join ", ", map { defined($_) ? $_ : "null" } @{$_[1]}{qw( Version Encoding Standalone )} );
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 4 2 6
201 }
202  
203 0 ▶sub entity_decl {
Subroutine entity_decl: not called CC=1 SCAR=6.9
Pod documented
204 # {Value,SystemId,PublicId,Notation}
205 0 HTTP::OAI::Debug::sax( $_[1]->{Name} );
206 }
207  
208 0 ▶sub unparsed_decl {
Subroutine unparsed_decl: not called CC=1 SCAR=6.9
Pod undocumented
209 0 HTTP::OAI::Debug::sax();
210 }
211  
212 0 ▶sub element_decl {
Subroutine element_decl: not called CC=1 SCAR=6.9
Pod documented
213 # {Model}
214 0 HTTP::OAI::Debug::sax( $_[1]->{Name} );
215 }
216  
217 0 ▶sub notation_decl {
Subroutine notation_decl: not called CC=1 SCAR=6.9
Pod documented
218 # {Name,Base,SystemId,PublicId}
219 0 HTTP::OAI::Debug::sax( $_[1]->{Name} );
220 }
221  
222 0 ▶sub processing_instruction {
Subroutine processing_instruction: not called CC=1 SCAR=6.9
Pod documented
223 # {Target,Data}
224 0 HTTP::OAI::Debug::sax( $_[1]->{Target} . " => " . $_[1]->{Data} );
225 }
226  
227 package HTTP::OAI::FilterDOMFragment;
228  
229 11 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
230  
231 11 @ISA = qw( XML::SAX::Base );
232  
233 # Trap things that don't apply to a balanced fragment
234 0 ▶sub start_document {}
Subroutine start_document: not called CC=1 SCAR=0.0
235 0 ▶sub end_document {}
Subroutine end_document: not called CC=1 SCAR=0.0
236 0 ▶sub xml_decl {}
Subroutine xml_decl: not called CC=1 SCAR=0.0
237  
238 package XML::SAX::Debug;
239  
240 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
241  
242 11 ▶use vars qw( @ISA $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
243  
244 11 @ISA = qw( XML::SAX::Base );
245  
246 0 ▶sub DEBUG {
Subroutine DEBUG: not called CC=1 SCAR=6.9
247 0 my ($event,$self,$hash) = @_;
248 0 warn "$event(".Dumper($hash).")\n";
249 0 my $superior = "SUPER::$event";
250 0 $self->$superior($hash);
251 }
252  
253 0 ▶sub start_document { DEBUG('start_document',@_) }
Subroutine start_document: not called CC=1 SCAR=6.9
254 0 ▶sub end_document { DEBUG('end_document',@_) }
Subroutine end_document: not called CC=1 SCAR=6.9
255 0 ▶sub start_element { DEBUG('start_element',@_) }
Subroutine start_element: not called CC=1 SCAR=6.9
256 0 ▶sub end_element { DEBUG('end_element',@_) }
Subroutine end_element: not called CC=1 SCAR=6.9
257 0 ▶sub characters { DEBUG('characters',@_) }
Subroutine characters: not called CC=1 SCAR=6.9
258 0 ▶sub xml_decl { DEBUG('xml_decl',@_) }
Subroutine xml_decl: not called CC=1 SCAR=6.9
259  
260 11 1;
261  
262 __END__
« lib/HTTP/OAI/Metadata/OAI_Identifier.pm ↑ Summary lib/HTTP/OAI/ListRecords.pm »