| 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{$_}
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_}
$defaults{$_}
Truth table66%2/3
A ||= B
A= $self->{$_}B= $defaults{$_}
| |||||||||||||||||||||||||||||
| 26 | 12 | ▶ | eval "require " . $self->{$_} or die $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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'} || ''
MC/DC100%1/1
$e->{'NamespaceURI'} || ''
$e->{'NamespaceURI'}
Truth table100%2/2
A
A= $e->{'NamespaceURI'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$contents and ref $contents->[-1] eq $class
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
| |||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$contents->[-1]->data || ''
$contents->[-1]->data
Truth table0%0/2
A
A= $contents->[-1]->data
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||