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