blib/lib/XML/Filter/SAXT.pm

filter: Statementstmt 26.0% 13 / 50 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 8.7% 2 / 23 Podpod 0.0% 0 / 21 totaltotal 14.0% 15 / 107 CC 10 SCAR 35.7
CC
10
Cov
21%
new
110.0
attlist_decl
1.9
characters
1.9
CRAP 35.6
↑ Summary
1 #
2 # To do:
3 # - later: ErrorHandler, Locale?
4  
5 package XML::Filter::SAXT;
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use vars qw( $VERSION %SAX_HANDLERS );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 $VERSION = 0.01;
10  
11 1 %SAX_HANDLERS = ( DocumentHandler =>
12 [ "start_document",
13 "end_document",
14 "start_element",
15 "end_element",
16 "characters",
17 "processing_instruction",
18 "comment",
19 "start_cdata",
20 "end_cdata",
21 "entity_reference",
22 "set_document_locator" # !! passes {Locator=>$perlsax}
23 ],
24  
25 DTDHandler =>
26 [ "notation_decl",
27 "unparsed_entity_decl",
28 "entity_decl",
29 "element_decl",
30 "attlist_decl",
31 "doctype_decl",
32 "xml_decl"
33 ],
34  
35 EntityResolver =>
36 [ "resolve_entity" ]);
37  
38 #
39 # Usage:
40 #
41 # $saxt = new XML::Filter::SAXT ( { Handler => $out0 },
42 # { DocumentHandler => $out1 },
43 # { DTDHandler => $out3,
44 # Handler => $out4
45 # }
46 # );
47 #
48 # $perlsax = new XML::Parser::PerlSAX ( Handler => $saxt );
49 # $perlsax->parse ( [OPTIONS] );
50 #
51 sub new
52 0 ▶{
Subroutine new: not called CC=10 SCAR=47.0
Pod undocumented
53 0 my ($class, @out) = @_;
54  
55 0 my $self = bless { Out => \@out }, $class;
56  
57 0 ▶ for (my $i = 0; $i < @out; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @out) 0 0 0
58 {
59 0 for my $handler (keys %SAX_HANDLERS)
60 {
61 0 my $callbacks = $SAX_HANDLERS{$handler};
62 0 ▶ my $h = ($self->{Out}->[$i]->{$handler} ||= $self->{Out}->[$i]->{Handler});
Condition0%0/3
$self->{"Out"}[$i]{$handler} ||= $self->{"Out"}[$i]{"Handler"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Out"}[$i]{$handler} ||= $self->{"Out"}[$i]{"Handler"}
$self->{"Out"}[$i]{$handler} $self->{"Out"}[$i]{"Handler"}
Truth table0%0/3
A ||= B
A= $self->{"Out"}[$i]{$handler}B= $self->{"Out"}[$i]{"Handler"}
ABresult
1X1
011
000
63 0 ▶ next unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 0 0 0
64  
65 0 for my $cb (@$callbacks)
66 {
67 0 ▶ if (UNIVERSAL::can ($h, $cb))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($h, $cb)) 0 0 0
68 {
69 0 $self->{$cb} .= "\$out->[$i]->{$handler}->$cb (\@_);\n";
70 }
71 }
72 }
73 }
74  
75 0 for my $handler (keys %SAX_HANDLERS)
76 {
77 0 my $callbacks = $SAX_HANDLERS{$handler};
78 0 for my $cb (@$callbacks)
79 {
80 0 my $code = $self->{$cb};
81 0 ▶ if (defined $code)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) { } 0 0 0
82 {
83 0 $self->{$cb} =
84 eval "sub { my \$out = shift->{Out}; $code }";
85 }
86 else
87 {
88 0 $self->{$cb} = \&noop;
89 }
90 }
91 }
92 0 return $self;
93 }
94
95 sub noop
96 0 ▶{
Subroutine noop: not called CC=1 SCAR=0.0
Pod undocumented
97 # does nothing
98 }
99  
100 1 for my $cb (map { @{ $_ } } values %SAX_HANDLERS)
101 {
102 0 ▶ eval "sub $cb { shift->{$cb}->(\@_); }";
Subroutine attlist_decl: not called CC=1 SCAR=6.2
Subroutine characters: not called CC=1 SCAR=6.2
Subroutine comment: not called CC=1 SCAR=6.2
Subroutine doctype_decl: not called CC=1 SCAR=6.2
Subroutine element_decl: not called CC=1 SCAR=6.2
Subroutine end_cdata: not called CC=1 SCAR=6.2
Subroutine end_document: not called CC=1 SCAR=6.2
Subroutine end_element: not called CC=1 SCAR=6.2
Subroutine entity_decl: not called CC=1 SCAR=6.2
Subroutine entity_reference: not called CC=1 SCAR=6.2
Subroutine notation_decl: not called CC=1 SCAR=6.2
Subroutine processing_instruction: not called CC=1 SCAR=6.2
Subroutine resolve_entity: not called CC=1 SCAR=6.2
Subroutine set_document_locator: not called CC=1 SCAR=6.2
Subroutine start_cdata: not called CC=1 SCAR=6.2
Subroutine start_document: not called CC=1 SCAR=6.2
Subroutine start_element: not called CC=1 SCAR=6.2
Subroutine unparsed_entity_decl: not called CC=1 SCAR=6.2
Subroutine xml_decl: not called CC=1 SCAR=6.2
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
103 }
104  
105 1 1; # package return code
106  
107 __END__
↑ Summary