PRANG/Graph/Text.pm

filter: Statementstmt 71.4% 35 / 49 Branchbran 62.5% 10 / 16 Conditioncond 25.0% 2 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 5 totaltotal 58.7% 54 / 92 SCAR 29.2
CC
12
Cov
64%
output
30.0
__ANON__
4.0
accept
3.0
CRAP 18.5
« PRANG/Graph/Quantity.pm ↑ Summary PRANG/Graph/Seq.pm »
1  
2 package PRANG::Graph::Text;
3 11 $PRANG::Graph::Text::VERSION = '0.19';
4 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 has 'attrName' =>
9 is => "ro",
10 isa => "Str",
11 ;
12  
13 11 has 'nodeName_attr' =>
14 is => "rw",
15 ;
16  
17 11 has 'xmlns_attr' =>
18 is => "rw",
19 ;
20  
21 has 'extra' =>
22 is => "ro",
23 isa => "ArrayRef",
24 lazy => 1,
25 default => sub {
26 29 ▶ my $self = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
27 29 my @extra;
28 29 ▶ if ( $self->nodeName_attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nodeName_attr) { } 2 27 29
29 2 push @extra, "";
30 }
31 else {
32 27 push @extra, undef;
33 }
34 29 ▶ if ( $self->xmlns_attr ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->xmlns_attr) { } 2 27 29
elsif (not defined $extra[0]) { } 27 0 27
35 2 push @extra, "";
36 }
37 elsif ( !defined $extra[0] ) {
38 27 pop @extra;
39 }
40 29 \@extra;
41 11 };
42  
43 sub node_ok {
44 69 ▶ my $self = shift;
Subroutine node_ok: called CC=3 SCAR=11.0
Pod undocumented
45 69 my ( $node, $ctx ) = pos_validated_list(
46 \@_,
47 { isa => 'XML::LibXML::Node' },
48 { isa => 'PRANG::Graph::Context' },
49 );
50
51 69 ▶ ( $node->nodeType == XML_TEXT_NODE
Branch: 1 branch
BranchTrueFalseTotal
$node->nodeType == 3 || $node->nodeType == 4 ? : 52 17 69
Condition66%2/3
$node->nodeType == 3 or $node->nodeType == 4
l!l&&r!l&&!r
52017
MC/DC50%1/2
$node->nodeType == 3 or $node->nodeType == 4
$node->nodeType == 3 $node->nodeType == 4
Truth table66%2/3
A or B
A= $node->nodeType == 3B= $node->nodeType == 4
ABresult
1X1
011
000
52 or
53 $node->nodeType == XML_CDATA_SECTION_NODE
54 )
55 ? 1 : undef;
56 }
57  
58 sub accept {
59 118 ▶ my $self = shift;
Subroutine accept: called CC=3 SCAR=11.1
Pod undocumented
60 118 my ( $node, $ctx ) = pos_validated_list(
61 \@_,
62 { isa => 'XML::LibXML::Node' },
63 { isa => 'PRANG::Graph::Context' },
64 { isa => 'Bool' },
65 );
66
67 118 ▶ if ( $node->nodeType == XML_TEXT_NODE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node->nodeType == 3) { } 117 1 118
elsif ($node->nodeType == 4) { } 1 0 1
68 117 ($self->attrName, $node->data, @{$self->extra});
69 }
70 elsif ( $node->nodeType == XML_CDATA_SECTION_NODE ) {
71 1 ($self->attrName, $node->data, @{$self->extra});
72 }
73 else {
74 0 $ctx->exception("expected text node", $node);
75 }
76 }
77  
78 sub complete{
79 0 ▶ 1;
Subroutine complete: not called CC=1 SCAR=6.9
Pod undocumented
80 }
81  
82 sub expected {
83 0 ▶ "TextNode";
Subroutine expected: not called CC=1 SCAR=6.9
Pod undocumented
84 }
85  
86 sub output {
87 0 ▶ my $self = shift;
Subroutine output: not called CC=5 SCAR=34.0
Pod undocumented
88 0 my ( $item, $node, $ctx, $value, $slot, $name ) = pos_validated_list(
89 \@_,
90 { isa => 'Object' },
91 { isa => 'XML::LibXML::Element' },
92 { isa => 'PRANG::Graph::Context' },
93 { isa => 'Item', optional => 1 },
94 { isa => 'Int', optional => 1 },
95 { isa => 'Str', optional => 1 },
96 );
97
98 0 ▶ $value //= do {
Condition0%0/3
$value //= do {
l!l&&r!l&&!r
000
MC/DC0%0/2
$value //= do { my $attrName = $self->attrName; $item->$attrName }
$value do { my $attrName = $self->attrName; $item->$attrName }
Truth table0%0/3
A //= B
A= $valueB= do { my $attrName = $self->attrName; $item->$attrName }
ABresult
1X1
011
000
99 0 my $attrName = $self->attrName;
100 0 $item->$attrName;
101 };
102 0 ▶ if ( ref $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 0 0 0
103 0 $value = $value->[$slot];
104 }
105 0 ▶ return unless length($value//"");
Branch: 1 branch
BranchTrueFalseTotal
unless length($value // "") 0 0 0
Condition0%0/2
$value // ""
l!l
00
MC/DC0%0/1
$value // ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
106 0 my $doc = $node->ownerDocument;
107 0 my $tn = $self->createTextNode($doc, $value);
108
109 0 $node->appendChild($tn);
110 }
111  
112 11 with 'PRANG::Graph::Node';
113  
114 11 1;
115  
116 __END__
117  
118 =head1 NAME
119  
120 PRANG::Graph::Text - accept an XML TextNode
121  
122 =head1 SYNOPSIS
123  
124 See L<PRANG::Graph::Meta::Element> source and
125 L<PRANG::Graph::Node> for examples and information.
126  
127 =head1 DESCRIPTION
128  
129 This graph node specifies that the XML graph at this point may contain
130 a text node. If it doesn't, this is considered equivalent to a
131 zero-length text node.
132  
133 If the element only has only complex children, it will not have one of
134 these objects in its graph.
135  
136 Along with L<PRANG::Graph::Element>, this graph node is the only type
137 which may actually consume input XML nodes or emit them on output.
138 The other node types merely change the state in the
139 L<PRANG::Graph::Context> object.
140  
141 =head1 ATTRIBUTES
142  
143 =over
144  
145 =item B<attrName>
146  
147 Used when emitting; specifies the method to call to retrieve the item
148 to be output. Also used when parsing, to return the Moose attribute
149 slot for construction.
150  
151 =back
152  
153 =head1 SEE ALSO
154  
155 L<PRANG::Graph::Meta::Class>, L<PRANG::Graph::Meta::Element>,
156 L<PRANG::Graph::Context>, L<PRANG::Graph::Node>
157  
158 =head1 AUTHOR AND LICENCE
159  
160 Development commissioned by NZ Registry Services, and carried out by
161 Catalyst IT - L<http://www.catalyst.net.nz/>
162  
163 Copyright 2009, 2010, NZ Registry Services. This module is licensed
164 under the Artistic License v2.0, which permits relicensing under other
165 Free Software licenses.
166  
167 =cut
168  
« PRANG/Graph/Quantity.pm ↑ Summary PRANG/Graph/Seq.pm »