ReutersConnect/XMLDocument.pm

filter: Statementstmt 21.9% 9 / 41 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 42.8% 3 / 7 Podpod n/a totaltotal 19.3% 12 / 62 CC 9 SCAR 22.8
CC
9
Cov
17%
_build_xml_namespaces
12.0
_build_xml_xpath
12.0
get_html_body
12.0
CRAP 9.8
« ReutersConnect/APIResponse.pm ↑ Summary ReutersConnect/Channel.pm »
1 package WebService::ReutersConnect::XMLDocument;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 my $LOGGER = Log::Log4perl->get_logger();
6  
7 has 'xml_document' => ( is => 'ro', required => 1 , handles => qr/.*/, isa => 'XML::LibXML::Document' );
8 has 'reuters' => ( is => 'ro', required => 1 , weak_ref => 1 , isa => 'WebService::ReutersConnect' );
9  
10 has 'xml_namespaces' => ( is => 'ro', lazy_build => 1, required => 1 );
11 has 'xml_xpath' => ( is => 'ro', lazy_build => 1 , required => 1 );
12  
13  
14 0 ▶sub _build_xml_namespaces{
Subroutine _build_xml_namespaces: not called CC=3 SCAR=24.8
15 0 my ($self) = @_;
16  
17 0 my %nss = ();
18  
19 ## Find default namespace.
20 0 my ( $default_ns ) = $self->xml_document->findnodes('/*/namespace::*[name()=\'\']');
21 0 $nss{''} = $default_ns;
22  
23 ## Find other namespace nodes.
24 0 my @ns_nodes = $self->xml_document->findnodes('/*/namespace::*[name()!=\'\']');
25 0 foreach my $ns_node ( @ns_nodes ){
26 0 ▶ $nss{$ns_node->getLocalName()} //= $ns_node;
Condition0%0/3
$nss{$ns_node->getLocalName} //= $ns_node
l!l&&r!l&&!r
000
MC/DC0%0/2
$nss{$ns_node->getLocalName} //= $ns_node
$nss{$ns_node->getLocalName} $ns_node
Truth table0%0/3
A //= B
A= $nss{$ns_node->getLocalName}B= $ns_node
ABresult
1X1
011
000
27 }
28  
29 0 my @namespaces = values %nss;
30 0 return \@namespaces;
31 }
32  
33 0 ▶sub _build_xml_xpath{
Subroutine _build_xml_xpath: not called CC=3 SCAR=24.8
34 0 my ($self) = @_;
35 0 my $xc = XML::LibXML::XPathContext->new( $self->xml_document() );
36 0 foreach my $ns_node ( @{$self->xml_namespaces()} ){
37 0 ▶ my $localname = $ns_node->getLocalName() // 'rcx';
Condition0%0/2
$ns_node->getLocalName // "rcx"
l!l
00
MC/DC0%0/1
$ns_node->getLocalName // "rcx"
$ns_node->getLocalName
Truth table0%0/2
A
A= $ns_node->getLocalName
Aresult
11
00
38 0 $LOGGER->info("Registering namespace $localname:".$ns_node->declaredURI());
39 0 $xc->registerNs( $localname , $ns_node->declaredURI() );
40 }
41 0 return $xc;
42 }
43  
44 0 ▶sub get_html_body{
Subroutine get_html_body: not called CC=3 SCAR=24.8
45 0 my ($self) = @_;
46 0 my ($body) = $self->xml_xpath->findnodes('//x:html/x:body');
47 0 ▶ unless( wantarray ){
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 0 0
48 0 return $body;
49 }
50  
51 0 ▶ unless( $body ){ return (); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($body) 0 0 0
52  
53 0 my @children = $body->nonBlankChildNodes();
54 0 return @children;
55 }
56  
57 0 ▶sub get_subjects{
Subroutine get_subjects: not called CC=3 SCAR=24.8
58 0 my ($self) = @_;
59 0 my @subject_nodes = $self->xml_xpath->findnodes('//rcx:contentMeta/rcx:subject');
60 0 my @concepts = ();
61 0 foreach my $subject_node ( @subject_nodes ){
62 0 ▶ if( my $concept = $self->reuters->_find_concept($subject_node->getAttribute('qcode'))){
Branch: 1 branch
BranchTrueFalseTotal
if (my $concept = $self->reuters->_find_concept($subject_node->getAttribute("qcode"))) 0 0 0
63 0 push @concepts , $concept;
64 }
65 }
66 0 return @concepts;
67 }
68  
69 __PACKAGE__->meta->make_immutable();
70 1;
71  
72 __END__
« ReutersConnect/APIResponse.pm ↑ Summary ReutersConnect/Channel.pm »