blib/lib/XML/SAX/Simple.pm

filter: Statementstmt 89.8% 44 / 49 Branchbran 70.0% 7 / 10 Conditioncond 50.0% 6 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 10 / 10 Podpod 66.6% 2 / 3 totaltotal 76.0% 70 / 92 CC 10 SCAR 13.1
CC
10
Cov
80%
build_tree
7.3
XMLout
3.6
XMLin
3.0
CRAP 3.7
↑ Summary
1 package XML::SAX::Simple;
2  
3 =head1 NAME
4  
5 XML::SAX::Simple - SAX version of XML::Simple.
6  
7 =head1 VERSION
8  
9 Version 0.04
10  
11 =cut
12  
13 7 $VERSION = '0.04';
14  
15 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 ▶use vars qw(@EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use XML::SAX;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use XML::Handler::Trees;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 7 ▶use base 'XML::Simple';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 @EXPORT = qw(XMLin XMLout);
24  
25 =head1 DESCRIPTION
26  
27 C<XML::SAX::Simple> is a very simple version of L<XML::Simple> but for SAX.It can
28 be used as a complete drop-in replacement for L<XML::Simple>.
29  
30 See the documentation for L<XML::Simple> for details.
31  
32 =head1 SYNOPSIS
33  
34 use XML::SAX::Simple qw(XMLin XMLout);
35 my $hash = XMLin("foo.xml");
36  
37 =cut
38  
39 sub XMLin {
40 19 ▶ my $self;
Subroutine XMLin: called CC=3 SCAR=11.0
Pod documented
41  
42 19 ▶ if ($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) { } 1 18 19
Condition66%2/3
$_[0] and UNIVERSAL::isa($_[0], "XML::Simple")
!ll&&!rl&&r
0181
MC/DC50%1/2
$_[0] and UNIVERSAL::isa($_[0], "XML::Simple")
$_[0] UNIVERSAL::isa($_[0], "XML::Simple")
Truth table66%2/3
A and B
A= $_[0]B= UNIVERSAL::isa($_[0], "XML::Simple")
ABresult
0X0
100
111
43 1 $self = shift;
44 }
45 else {
46 18 $self = XML::SAX::Simple->new();
47 }
48  
49 19 $self->SUPER::XMLin(@_);
50 }
51  
52 sub XMLout {
53 1 ▶ my $self;
Subroutine XMLout: called CC=3 SCAR=12.7
Pod documented
54  
55 1 ▶ if ($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and UNIVERSAL::isa($_[0], 'XML::Simple')) { } 0 1 1
Condition33%1/3
$_[0] and UNIVERSAL::isa($_[0], "XML::Simple")
!ll&&!rl&&r
010
MC/DC0%0/2
$_[0] and UNIVERSAL::isa($_[0], "XML::Simple")
$_[0] UNIVERSAL::isa($_[0], "XML::Simple")
Truth table33%1/3
A and B
A= $_[0]B= UNIVERSAL::isa($_[0], "XML::Simple")
ABresult
0X0
100
111
56 0 $self = shift;
57 }
58 else {
59 1 $self = XML::SAX::Simple->new();
60 }
61  
62 1 $self->SUPER::XMLout(@_);
63 }
64  
65 sub build_tree {
66 14 ▶ my ($self, $filename, $string) = @_;
Subroutine build_tree: called CC=6 SCAR=19.9
Pod undocumented
67  
68 14 $self->{nocollapse} = 1;
69  
70 14 ▶ if ($filename and $filename eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename and $filename eq "-") 0 14 14
Condition66%2/3
$filename and $filename eq "-"
!ll&&!rl&&r
3110
MC/DC0%0/2
$filename and $filename eq "-"
$filename $filename eq "-"
Truth table66%2/3
A and B
A= $filenameB= $filename eq "-"
ABresult
0X0
100
111
71 0 local($/);
72 0 $string = <STDIN>;
73 0 $filename = undef;
74 }
75  
76 14 my $handler = XML::Handler::Tree->new();
77 14 my $parser = XML::SAX::ParserFactory->parser(Handler => $handler);
78  
79 14 my $tree;
80  
81 14 ▶ if ($filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) { } 11 3 14
82 11 $tree = $parser->parse_uri($filename);
83 }
84 else {
85 3 ▶ if (ref($string) && ref($string) ne 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $string and ref $string ne 'SCALAR') { } 0 3 3
Condition33%1/3
ref $string and ref $string ne "SCALAR"
!ll&&!rl&&r
030
MC/DC0%0/2
ref $string and ref $string ne "SCALAR"
ref $string ref $string ne "SCALAR"
Truth table33%1/3
A and B
A= ref $stringB= ref $string ne "SCALAR"
ABresult
0X0
100
111
86 0 $tree = $parser->parse_file($string);
87 }
88 else {
89 3 $tree = $parser->parse_string($string);
90 }
91 }
92  
93 11 return $tree;
94 }
95  
96 =head1 AUTHOR
97  
98 Matt Sergeant, matt@sergeant.org
99  
100 Currently maintained by Mohammad S Anwar (MANWAR), C<< <mohammad.anwar AT yahoo.com> >>
101  
102 =head1 SEE ALSO
103  
104 L<XML::Simple>, L<XML::SAX>.
105  
106 =head1 COPYRIGHT AND LICENCE
107  
108 This is free software. You may use it and distribute it under the same terms as
109 Perl itself.
110  
111 Copyright (C) 2001 Matt Sergeant, matt@sergeant.org
112  
113 =cut
114  
115 7 1; # end of XML::SAX::Simple
↑ Summary