blib/lib/XML/XPath/Diver.pm

filter: Statementstmt 100% 11 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 15 / 15 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package XML::XPath::Diver;
2 2 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use parent 'XML::XPath';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 use XML::XPath::XMLParser;
7 use Class::Builtin ();
8  
9 our $VERSION = "0.02";
10  
11 sub dive {
12 my ($self, $xpath) = @_;
13 my $nodeset = $self->find($xpath);
14 my @nodes = map {__PACKAGE__->new(xml => XML::XPath::XMLParser::as_string($_))} $nodeset->get_nodelist;
15 wantarray ? @nodes : Class::Builtin->can('OO')->([@nodes]);
16 }
17  
18 sub attr {
19 my ($self, $attr_name) = @_;
20 my $nodeset = $self->find(sprintf('//@%s', $attr_name));
21 my $node = $nodeset->shift;
22 $node->getNodeValue;
23 }
24  
25 sub text { shift->getNodeText(shift || '/')->value }
26  
27 sub to_string {
28 my $self = shift;
29 my $nodeset = $self->find('/');
30 XML::XPath::XMLParser::as_string($nodeset->shift);
31 }
32  
33 1;
34 __END__
↑ Summary