line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Diver; |
2
|
3
|
|
|
3
|
|
52221
|
use 5.008005; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
126
|
|
3
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
103
|
|
4
|
3
|
|
|
3
|
|
22
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
103
|
|
5
|
3
|
|
|
3
|
|
3122
|
use parent 'XML::LibXML::XPathContext'; |
|
3
|
|
|
|
|
1139
|
|
|
3
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
use XML::LibXML; |
7
|
|
|
|
|
|
|
use Class::Builtin (); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub load_xml { |
12
|
|
|
|
|
|
|
my ($class, %opts) = @_; |
13
|
|
|
|
|
|
|
my $node = XML::LibXML->load_xml(%opts); |
14
|
|
|
|
|
|
|
$class->new($node); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub dive { |
18
|
|
|
|
|
|
|
my ($self, $xpath) = @_; |
19
|
|
|
|
|
|
|
my $nodeset = $self->find($xpath); |
20
|
|
|
|
|
|
|
my @nodes = map {__PACKAGE__->load_xml(string => $_->toStringC14N)} $nodeset->get_nodelist; |
21
|
|
|
|
|
|
|
wantarray ? @nodes : Class::Builtin->can('OO')->([@nodes]); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub attr { |
25
|
|
|
|
|
|
|
my ($self, $attr_name) = @_; |
26
|
|
|
|
|
|
|
my $nodeset = $self->find(sprintf('//@%s', $attr_name)); |
27
|
|
|
|
|
|
|
my $node = $nodeset->shift; |
28
|
|
|
|
|
|
|
$node->value; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub text { shift->findvalue('/') } |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub to_string { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my $nodeset = $self->find('/'); |
36
|
|
|
|
|
|
|
$nodeset->shift->toStringC14N; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
__END__ |