lib/XML/Toolset/Document.pm

filter: Statementstmt 12.6% 11 / 87 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 23.0% 3 / 13 Podpod 0.0% 0 / 10 totaltotal 7.2% 14 / 194 CC 36 SCAR 46.0
CC
36
Cov
7%
new
272.0
dom
20.0
xml
20.0
CRAP 99.3
↑ Summary blib/lib/XML/Toolset/DOM.pm »
1 package XML::Toolset::Document;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 $VERSION = sprintf"%d.%03d", q$Revision: 1.9 $ =~ /: (\d+)\.(\d+)/;
7  
8 1 ▶use XML::Toolset;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub new {
Subroutine new: not called CC=16 SCAR=56.1
Pod undocumented
11 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
12 0 my $this = shift;
13 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
14 0 my ($lone_arg);
15 0 ▶ $lone_arg = shift if ($#_ > -1 && $#_ % 2 == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $#_ > -1 and $#_ % 2 == 0 0 0 0
Condition0%0/3
$#_ > -1 and $#_ % 2 == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ > -1 and $#_ % 2 == 0
$#_ > -1 $#_ % 2 == 0
Truth table0%0/3
A and B
A= $#_ > -1B= $#_ % 2 == 0
ABresult
0X0
100
111
16 0 my $self = { @_ };
17 0 ▶ if ($lone_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lone_arg) 0 0 0
18 0 ▶ if (ref($lone_arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $lone_arg) { } 0 0 0
19 0 ▶ $self->{dom} = $lone_arg if (!$self->{dom});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dom"} 0 0 0
20 }
21 else {
22 0 ▶ $self->{xml} = $lone_arg if (!$self->{xml});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"xml"} 0 0 0
23 }
24 }
25 0 ▶ die "an XML document must be initialized with an xml_toolset" if (!$self->{xml_toolset});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"xml_toolset"} 0 0 0
26 0 ▶ if (!$self->{dom} && !$self->{xml} && $self->{root_element}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"dom"} || $self->{"xml"} and $self->{"root_element"}) 0 0 0
Condition0%0/6
not $self->{"dom"} || $self->{"xml"} and $self->{"root_element"}
!ll&&!rl&&r
000
$self->{'dom'} || $self->{'xml'}
l!l&&r!l&&!r
000
MC/DC0%0/3
not $self->{"dom"} || $self->{"xml"} and $self->{"root_element"}
$self->{'dom'} $self->{'xml'} $self->{"root_element"}
Truth table0%0/4
not(A || B) and C
A= $self->{'dom'}B= $self->{'xml'}C= $self->{"root_element"}
ABCresult
1XX0
01X0
0000
0011
27 0 $self->{dom} = $self->{xml_toolset}->new_dom($self->{root_element}, $self->{xmlns});
28 }
29 0 ▶ die "an XML document must be initialized with either a DOM or the XML" if (!$self->{dom} && !$self->{xml});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dom"} or $self->{"xml"} 0 0 0
Condition0%0/3
$self->{"dom"} or $self->{"xml"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dom"} or $self->{"xml"}
$self->{"dom"} $self->{"xml"}
Truth table0%0/3
A or B
A= $self->{"dom"}B= $self->{"xml"}
ABresult
1X1
011
000
30 0 bless $self, $class;
31 0 ▶ &App::sub_exit($self) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
32 0 return($self);
33 }
34  
35 0 ▶sub dom {
Subroutine dom: not called CC=4 SCAR=30.0
Pod undocumented
36 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
37 0 my ($self) = @_;
38 0 my $dom = $self->{dom};
39 0 ▶ if (!$dom) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dom) 0 0 0
40 0 my $xml_toolset = $self->{xml_toolset};
41 0 $dom = $xml_toolset->parse($self->{xml});
42 0 $self->{dom} = $dom;
43 }
44 0 ▶ &App::sub_exit($dom) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
45 0 return($dom);
46 }
47  
48 0 ▶sub xml {
Subroutine xml: not called CC=4 SCAR=30.0
Pod undocumented
49 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
50 0 my ($self) = @_;
51 0 my $xml = $self->{xml};
52 0 ▶ if (!$xml) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xml) 0 0 0
53 0 my $xml_toolset = $self->{xml_toolset};
54 0 $xml = $xml_toolset->to_string($self);
55 0 $self->{xml} = $xml;
56 }
57 0 ▶ &App::sub_exit($xml) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
58 0 return($xml);
59 }
60  
61 0 ▶sub to_string {
Subroutine to_string: not called CC=3 SCAR=24.8
Pod undocumented
62 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
63 0 my ($self) = @_;
64 0 my $xml = $self->xml();
65 0 ▶ &App::sub_exit($xml) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
66 0 return($xml);
67 }
68  
69 0 ▶sub get_root_tag {
Subroutine get_root_tag: not called CC=3 SCAR=24.8
Pod undocumented
70 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
71 0 my ($self) = @_;
72 0 my $xml_toolset = $self->{xml_toolset};
73 0 my $root_tag = $xml_toolset->get_root_tag($self->xml());
74 0 ▶ &App::sub_exit($root_tag) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
75 0 return($root_tag);
76 }
77  
78 0 ▶sub get_first_tag {
Subroutine get_first_tag: not called CC=3 SCAR=24.8
Pod undocumented
79 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
80 0 my ($self, $xpath) = @_;
81 0 my $xml_toolset = $self->{xml_toolset};
82 0 my $first_tag = $xml_toolset->get_first_tag($self->dom(), $xpath);
83 0 ▶ &App::sub_exit($first_tag) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
84 0 return($first_tag);
85 }
86  
87 0 ▶sub validate {
Subroutine validate: not called CC=3 SCAR=24.8
Pod undocumented
88 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
89 0 my ($self, $options) = @_;
90 0 my $xml_toolset = $self->{xml_toolset};
91 0 my $is_valid = $xml_toolset->validate_document($self->xml(), $options);
92 0 ▶ &App::sub_exit($is_valid) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
93 0 return($is_valid);
94 }
95  
96 0 ▶sub get_value {
Subroutine get_value: not called CC=3 SCAR=24.8
Pod undocumented
97 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
98 0 my ($self, $xpath, $value) = @_;
99 0 my $xml_toolset = $self->{xml_toolset};
100 0 my $result = $xml_toolset->get_value($self->dom(), $xpath);
101 0 ▶ &App::sub_exit($result) if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
102 0 return($result);
103 }
104  
105 0 ▶sub set_value {
Subroutine set_value: not called CC=3 SCAR=24.8
Pod undocumented
106 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
107 0 my ($self, $xpath, $value) = @_;
108 0 my $xml_toolset = $self->{xml_toolset};
109 0 $xml_toolset->set_value($self->dom(), $xpath, $value);
110 0 delete $self->{xml};
111 0 ▶ &App::sub_exit() if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
112 }
113  
114 0 ▶sub transform {
Subroutine transform: not called CC=3 SCAR=24.8
Pod undocumented
115 0 ▶ &App::sub_entry if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
116 0 my ($self, $transform_name) = @_;
117 0 my $xml_toolset = $self->{xml_toolset};
118 0 $xml_toolset->transform($self->dom(), $transform_name);
119 0 delete $self->{xml};
120 0 ▶ &App::sub_exit() if ($App::trace);
Branch: 1 branch
BranchTrueFalseTotal
if $App::trace 0 0 0
121 }
122  
123 1 1;
124  
125 =head1 NAME
126  
127 XML::Toolset::Document - An object which represents an XML document which knows about an XML::Toolset implementation which can perform operations on it.
128  
129 =head1 SYNOPSIS
130  
131 use XML::Toolset::Document;
132 my $xml = <<EOF;
133 <hello world="!">
134 How are you?
135 <how>
136 <ya doing="?" />
137 </how>
138 </hello>
139 EOF
140 my $doc = XML::Toolset::Document->new($xml);
141
142 my $final_xml = $doc->to_string();
143  
144 =head1 DESCRIPTION
145  
146 An XML::Toolset::Document object represents an XML document which knows about an
147 XML::Toolset implementation which can perform operations on it.
148  
149 Sorry. There's no more documentation yet except the code.
150  
151 =head1 AUTHOR
152  
153 Stephen Adkins <spadkins@gmail.com>
154  
155 =head1 COPYRIGHT
156  
157 (c) 2007 Stephen Adkins, for the purpose of making it Free.
158 This is Free Software. It is licensed under the same terms as Perl itself.
159  
160 =cut
↑ Summary blib/lib/XML/Toolset/DOM.pm »