line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package PRANG::Graph::Text; |
3
|
|
|
|
|
|
|
$PRANG::Graph::Text::VERSION = '0.19'; |
4
|
1
|
|
|
1
|
|
1682
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
5836
|
use MooseX::Params::Validate; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
601
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'attrName' => |
9
|
|
|
|
|
|
|
is => "ro", |
10
|
|
|
|
|
|
|
isa => "Str", |
11
|
|
|
|
|
|
|
; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'nodeName_attr' => |
14
|
|
|
|
|
|
|
is => "rw", |
15
|
|
|
|
|
|
|
; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'xmlns_attr' => |
18
|
|
|
|
|
|
|
is => "rw", |
19
|
|
|
|
|
|
|
; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'extra' => |
22
|
|
|
|
|
|
|
is => "ro", |
23
|
|
|
|
|
|
|
isa => "ArrayRef", |
24
|
|
|
|
|
|
|
lazy => 1, |
25
|
|
|
|
|
|
|
default => sub { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
my @extra; |
28
|
|
|
|
|
|
|
if ( $self->nodeName_attr ) { |
29
|
|
|
|
|
|
|
push @extra, ""; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
|
|
|
|
|
|
push @extra, undef; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
if ( $self->xmlns_attr ) { |
35
|
|
|
|
|
|
|
push @extra, ""; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ( !defined $extra[0] ) { |
38
|
|
|
|
|
|
|
pop @extra; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
\@extra; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub node_ok { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
my ( $node, $ctx ) = pos_validated_list( |
46
|
|
|
|
|
|
|
\@_, |
47
|
|
|
|
|
|
|
{ isa => 'XML::LibXML::Node' }, |
48
|
|
|
|
|
|
|
{ isa => 'PRANG::Graph::Context' }, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
( $node->nodeType == XML_TEXT_NODE |
52
|
|
|
|
|
|
|
or |
53
|
|
|
|
|
|
|
$node->nodeType == XML_CDATA_SECTION_NODE |
54
|
|
|
|
|
|
|
) |
55
|
|
|
|
|
|
|
? 1 : undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub accept { |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
my ( $node, $ctx ) = pos_validated_list( |
61
|
|
|
|
|
|
|
\@_, |
62
|
|
|
|
|
|
|
{ isa => 'XML::LibXML::Node' }, |
63
|
|
|
|
|
|
|
{ isa => 'PRANG::Graph::Context' }, |
64
|
|
|
|
|
|
|
{ isa => 'Bool' }, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if ( $node->nodeType == XML_TEXT_NODE ) { |
68
|
|
|
|
|
|
|
($self->attrName, $node->data, @{$self->extra}); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif ( $node->nodeType == XML_CDATA_SECTION_NODE ) { |
71
|
|
|
|
|
|
|
($self->attrName, $node->data, @{$self->extra}); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
|
|
|
|
|
|
$ctx->exception("expected text node", $node); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub complete{ |
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub expected { |
83
|
|
|
|
|
|
|
"TextNode"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub output { |
87
|
|
|
|
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
$value //= do { |
99
|
|
|
|
|
|
|
my $attrName = $self->attrName; |
100
|
|
|
|
|
|
|
$item->$attrName; |
101
|
|
|
|
|
|
|
}; |
102
|
|
|
|
|
|
|
if ( ref $value ) { |
103
|
|
|
|
|
|
|
$value = $value->[$slot]; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
return unless length($value//""); |
106
|
|
|
|
|
|
|
my $doc = $node->ownerDocument; |
107
|
|
|
|
|
|
|
my $tn = $self->createTextNode($doc, $value); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$node->appendChild($tn); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
with 'PRANG::Graph::Node'; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|