Elemental/SAXHandler.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 50.0% 3 / 6 Conditioncond 50.0% 5 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 11 / 11 Podpod 83.3% 5 / 6 totaltotal 83.8% 83 / 99 CC 9 SCAR 10.2
CC
9
Cov
87%
characters
4.8
new
4.1
start_element
3.0
CRAP 2.8
« Elemental/Util.pm ↑ Summary Elemental/Element.pm »
1 package XML::Elemental::SAXHandler;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 $VERSION = '0.11';
7  
8 3 ▶use base qw( XML::SAX::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 my %defaults = (
13 Document => 'XML::Elemental::Document',
14 Element => 'XML::Elemental::Element',
15 Characters => 'XML::Elemental::Characters'
16 );
17  
18 # We work with direct references to the underlying HASH data
19 # rather then the methods for better parsing performance.
20 # Dangerous? Perhaps.
21  
22 4 ▶sub new {
Subroutine new: called CC=4 SCAR=14.2
Pod undocumented
23 4 my $self = shift->SUPER::new(@_);
24 4 for (keys %defaults) {
25 12 ▶ $self->{$_} ||= $defaults{$_};
Condition66%2/3
$self->{$_} ||= $defaults{$_}
l!l&&r!l&&!r
390
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_} $defaults{$_}
Truth table66%2/3
A ||= B
A= $self->{$_}B= $defaults{$_}
ABresult
1X1
011
000
26 12 ▶ eval "require " . $self->{$_} or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval 'require ' . $self->{$_} or die $@ 12 0 12
27 }
28 4 $self;
29 }
30  
31 3 ▶sub start_document {
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
32 3 my ($self, $doc) = @_;
33 3 $self->{__doc} = $self->{Document}->new;
34 3 push(@{$self->{__stack}}, $self->{__doc});
35 }
36  
37 15 ▶sub start_element {
Subroutine start_element: called CC=3 SCAR=11.0
Pod documented
38 15 my ($self, $e) = @_;
39 15 ▶ my $ns = $e->{NamespaceURI} || '';
Condition100%2/2
$e->{'NamespaceURI'} || ''
l!l
96
MC/DC100%1/1
$e->{'NamespaceURI'} || ''
$e->{'NamespaceURI'}
Truth table100%2/2
A
A= $e->{'NamespaceURI'}
Aresult
11
00
40 15 my $node = $self->{Element}->new;
41 15 $node->{name} = "{$ns}" . $e->{LocalName};
42 15 $node->{parent} = $self->{__stack}->[-1];
43 15 ▶ if ($e->{Attributes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"Attributes"}) 15 0 15
44 15 my %attr;
45 18 map { $attr{$_} = $e->{Attributes}->{$_}->{Value} }
46 15 keys %{$e->{Attributes}};
47 15 $node->{attributes} = \%attr;
48 }
49 15 push(@{$node->{parent}->{contents}}, $node);
50 15 push(@{$self->{__stack}}, $node);
51 }
52  
53 24 ▶sub characters {
Subroutine characters: called CC=4 SCAR=15.7
Pod documented
54 24 my ($self, $data) = @_;
55 24 my $parent = $self->{__stack}->[-1];
56 24 my $contents = $parent->{contents};
57 24 my $class = $self->{Characters};
58 24 ▶ unless ($contents && ref($contents->[-1]) eq $class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents and ref $contents->[-1] eq $class) { } 0 24 24
Condition33%1/3
$contents and ref $contents->[-1] eq $class
!ll&&!rl&&r
0240
MC/DC0%0/2
$contents and ref $contents->[-1] eq $class
$contents ref $contents->[-1] eq $class
Truth table33%1/3
A and B
A= $contentsB= ref $contents->[-1] eq $class
ABresult
0X0
100
111
59 24 my $node = $class->new;
60 24 $node->{parent} = $parent;
61 24 $node->{data} = $data->{Data};
62 24 push(@{$contents}, $node);
63 }
64 else {
65 0 ▶ my $d = $contents->[-1]->data || '';
Condition0%0/2
$contents->[-1]->data || ''
l!l
00
MC/DC0%0/1
$contents->[-1]->data || ''
$contents->[-1]->data
Truth table0%0/2
A
A= $contents->[-1]->data
Aresult
11
00
66 0 $contents->[-1]->data($d . $data->{Data});
67 }
68 }
69  
70 15 ▶sub end_element { pop(@{$_[0]->{__stack}}) }
Subroutine end_element: called CC=1 SCAR=0.0
Pod documented
71  
72 3 ▶sub end_document {
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
73 3 delete $_[0]->{__stack};
74 3 $_[0]->{__doc}->{contents} = $_[0]->{__doc}->{contents}->[0];
75 3 weaken($_[0]->{__doc}->{contents}->{parent} = $_[0]->{__doc});
76 3 $_[0]->{__doc};
77 }
78  
79 3 1;
80  
81 __END__
« Elemental/Util.pm ↑ Summary Elemental/Element.pm »