line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Struct; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
168280
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
1288
|
|
4
|
5
|
|
|
5
|
|
15317
|
use XML::LibXML::Reader; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XML::Struct::Reader; |
6
|
|
|
|
|
|
|
use XML::Struct::Writer; |
7
|
|
|
|
|
|
|
use XML::Struct::Simple; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(readXML writeXML simpleXML removeXMLAttr textValues); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub readXML { # ( [$from], %options ) |
14
|
|
|
|
|
|
|
my (%options) = @_ % 2 ? (from => @_) : @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %reader_options = ( |
17
|
|
|
|
|
|
|
map { $_ => delete $options{$_} } |
18
|
|
|
|
|
|
|
grep { exists $options{$_} } |
19
|
|
|
|
|
|
|
qw(attributes whitespace path stream simple micro root ns depth content deep) |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
if (%options) { |
22
|
|
|
|
|
|
|
if (exists $options{from} and keys %options == 1) { |
23
|
|
|
|
|
|
|
$reader_options{from} = $options{from}; |
24
|
|
|
|
|
|
|
} else { |
25
|
|
|
|
|
|
|
$reader_options{from} = \%options; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
XML::Struct::Reader->new( %reader_options )->readDocument; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub writeXML { |
33
|
|
|
|
|
|
|
my ($xml, %options) = @_; |
34
|
|
|
|
|
|
|
XML::Struct::Writer->new(%options)->write($xml); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub simpleXML { |
38
|
|
|
|
|
|
|
my ($element, %options) = @_; |
39
|
|
|
|
|
|
|
XML::Struct::Simple->new(%options)->transform($element); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
*removeXMLAttr = *XML::Struct::Simple::removeXMLAttr; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# TODO: document (better name?) |
45
|
|
|
|
|
|
|
sub textValues { |
46
|
|
|
|
|
|
|
my ($element, $options) = @_; |
47
|
|
|
|
|
|
|
# TODO: %options (e.g. join => " ") |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $children = $element->[2]; |
50
|
|
|
|
|
|
|
return "" if !$children; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return join "", grep { $_ ne "" } map { |
53
|
|
|
|
|
|
|
ref $_ ? textValues($_, $options) : $_ |
54
|
|
|
|
|
|
|
} @$children; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
__END__ |