line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::AlephX::XPath::Helper; |
2
|
25
|
|
|
25
|
|
115953
|
use Catmandu::Sane; |
|
25
|
|
|
|
|
185026
|
|
|
25
|
|
|
|
|
129
|
|
3
|
25
|
|
|
25
|
|
17760
|
use XML::LibXML; |
|
25
|
|
|
|
|
994665
|
|
|
25
|
|
|
|
|
153
|
|
4
|
25
|
|
|
25
|
|
3511
|
use XML::LibXML::XPathContext; |
|
25
|
|
|
|
|
50
|
|
|
25
|
|
|
|
|
554
|
|
5
|
25
|
|
|
25
|
|
125
|
use Catmandu::Util qw(:is io); |
|
25
|
|
|
|
|
47
|
|
|
25
|
|
|
|
|
6102
|
|
6
|
25
|
|
|
25
|
|
158
|
use Exporter qw(import); |
|
25
|
|
|
|
|
45
|
|
|
25
|
|
|
|
|
10068
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK=qw(get_children xpath); |
8
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all=>[@EXPORT_OK]); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "1.071"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_children { |
13
|
0
|
|
|
0
|
0
|
|
my($xpath,$is_hash) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $hash = {}; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
if($xpath){ |
18
|
0
|
|
|
|
|
|
for my $child($xpath->find('child::*')->get_nodelist()){ |
19
|
0
|
|
|
|
|
|
my $name = $child->nodeName(); |
20
|
0
|
|
|
|
|
|
my $value = $child->textContent(); |
21
|
0
|
0
|
|
|
|
|
if($is_hash){ |
22
|
0
|
|
|
|
|
|
$hash->{ $name } = $value; |
23
|
|
|
|
|
|
|
}else{ |
24
|
0
|
|
0
|
|
|
|
$hash->{$name} //= []; |
25
|
0
|
0
|
|
|
|
|
push @{ $hash->{$name} },$value if is_string($value); |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$hash; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub xpath { |
34
|
0
|
|
|
0
|
0
|
|
my $str = $_[0]; |
35
|
0
|
|
|
|
|
|
my $xpath; |
36
|
0
|
0
|
|
|
|
|
if(is_scalar_ref($str)){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $xml = XML::LibXML->load_xml(IO => io($str)); |
38
|
0
|
|
|
|
|
|
$xpath = XML::LibXML::XPathContext->new($xml); |
39
|
|
|
|
|
|
|
}elsif(-f $str){ |
40
|
0
|
|
|
|
|
|
my $xml = XML::LibXML->load_xml(location => $str); |
41
|
0
|
|
|
|
|
|
$xpath = XML::LibXML::XPathContext->new($xml); |
42
|
|
|
|
|
|
|
}elsif(is_glob_ref($str)){ |
43
|
0
|
|
|
|
|
|
my $xml = XML::LibXML->load_xml(IO => io($str)); |
44
|
0
|
|
|
|
|
|
$xpath = XML::LibXML::XPathContext->new($xml); |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
return $xpath; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |