Rabbit/Role/Document.pm

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 92.1% 59 / 64 CC 7 SCAR 13.5
CC
7
Cov
94%
_build__document
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.9
« Rabbit/Trait/XPath.pm ↑ Summary Rabbit/Trait/XPathValueMap.pm »
1 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package XML::Rabbit::Role::Document;
5 {
6 14 $XML::Rabbit::Role::Document::VERSION = '0.4.0';
7 }
8 14 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 14 ▶use XML::LibXML 1.69 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # ABSTRACT: XML Document base class
14  
15  
16 14 has '_file' => (
17 is => 'ro',
18 isa => 'Str',
19 init_arg => 'file',
20 predicate => '_has_file',
21 );
22  
23  
24 14 has '_fh' => (
25 is => 'ro',
26 isa => 'GlobRef',
27 init_arg => 'fh',
28 predicate => '_has_fh',
29 );
30  
31  
32 14 has '_xml' => (
33 is => 'ro',
34 isa => 'Str',
35 init_arg => 'xml',
36 predicate => '_has_xml',
37 );
38  
39  
40 14 has '_document' => (
41 is => 'ro',
42 isa => 'XML::LibXML::Document',
43 lazy_build => 1,
44 init_arg => 'dom',
45 );
46  
47 sub _build__document {
48 13 ▶ my ( $self ) = @_;
Subroutine _build__document: called CC=7 SCAR=19.7
49 13 my $doc;
50 # Priority source order is: file, fh, xml (string) if multiple defined
51 13 ▶ $doc = $self->_parser->parse_file( $self->_file ) if $self->_has_file;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_file 11 2 13
52 13 ▶ $doc = $self->_parser->parse_fh( $self->_fh ) if $self->_has_fh and not defined($doc);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_fh and not defined $doc 1 12 13
Condition66%2/3
$self->_has_fh and not defined $doc
!ll&&!rl&&r
1201
MC/DC50%1/2
$self->_has_fh and not defined $doc
$self->_has_fh not defined $doc
Truth table66%2/3
A and not(B)
A= $self->_has_fhB= not defined $doc
ABresult
0X0
100
111
53 13 ▶ $doc = $self->_parser->parse_string( $self->_xml ) if $self->_has_xml and not defined($doc);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_xml and not defined $doc 1 12 13
Condition66%2/3
$self->_has_xml and not defined $doc
!ll&&!rl&&r
1201
MC/DC50%1/2
$self->_has_xml and not defined $doc
$self->_has_xml not defined $doc
Truth table66%2/3
A and not(B)
A= $self->_has_xmlB= not defined $doc
ABresult
0X0
100
111
54 13 ▶ confess("No input specified. Please specify argument file, fh, xml or dom.\n") unless $doc;
Branch: 1 branch
BranchTrueFalseTotal
unless $doc 0 13 13
55 13 return $doc;
56 }
57  
58 has '_parser' => (
59 is => 'ro',
60 isa => 'XML::LibXML',
61 lazy => 1,
62 13 ▶ default => sub { XML::LibXML->new(), },
Subroutine __ANON__: called CC=1 SCAR=0.0
63 14 );
64  
65  
66 sub dump_document_xml {
67 1 ▶ my ( $self ) = @_;
Subroutine dump_document_xml: called CC=1 SCAR=0.0
Pod documented
68 1 return Encode::decode(
69 $self->_document->actualEncoding,
70 $self->_document->toString(1),
71 );
72 }
73  
74 14 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 14 1;
77  
78 __END__
79  
80 =pod
81  
82 =encoding utf-8
83  
84 =head1 NAME
85  
86 XML::Rabbit::Role::Document - XML Document base class
87  
88 =head1 VERSION
89  
90 version 0.4.0
91  
92 =head1 SYNOPSIS
93  
94 package MyXMLSyntax;
95 use Moose;
96 with 'XML::Rabbit::Role::Document';
97  
98 sub root_node {
99 return shift->_document->documentElement();
100 }
101  
102 =head1 DESCRIPTION
103  
104 This module provides the base document attribute used to hold the parsed XML content.
105  
106 See L<XML::Rabbit> for a more complete example.
107  
108 =head1 ATTRIBUTES
109  
110 =head2 _file
111  
112 A string representing the path to the file that contains the XML document data. Read Only. Constructor parameter is C<file>.
113  
114 =head2 _fh
115  
116 A glob reference / file handle that points to the XML document data. Read Only. Constructor parameter is C<fh>.
117  
118 =head2 _xml
119  
120 A binary string containing the XML document data. Read Only. Constructor parameter is C<xml>.
121  
122 =head2 _document
123  
124 An instance of an L<XML::LibXML::Document> class. Read Only. Constructor parameter is C<dom>.
125  
126 =head1 METHODS
127  
128 =head2 dump_document_xml
129  
130 Dumps the XML of the entire document as a native perl string.
131  
132 =head1 AUTHOR
133  
134 Robin Smidsrød <robin@smidsrod.no>
135  
136 =head1 COPYRIGHT AND LICENSE
137  
138 This software is copyright (c) 2013 by Robin Smidsrød.
139  
140 This is free software; you can redistribute it and/or modify it under
141 the same terms as the Perl 5 programming language system itself.
142  
143 =cut
« Rabbit/Trait/XPath.pm ↑ Summary Rabbit/Trait/XPathValueMap.pm »