| 1 | |||||||||||||||||||||||||||||
| 2 | package PRANG::Graph::Text; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use MooseX::Method::Signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | has 'attrName' => | |||||||||||||||||||||||||||
| 9 | is => "ro", | ||||||||||||||||||||||||||||
| 10 | isa => "Str", | ||||||||||||||||||||||||||||
| 11 | ; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | has 'nodeName_attr' => | |||||||||||||||||||||||||||
| 14 | is => "rw", | ||||||||||||||||||||||||||||
| 15 | ; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 9 | has 'xmlns_attr' => | |||||||||||||||||||||||||||
| 18 | is => "rw", | ||||||||||||||||||||||||||||
| 19 | ; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | has 'extra' => | ||||||||||||||||||||||||||||
| 22 | is => "ro", | ||||||||||||||||||||||||||||
| 23 | isa => "ArrayRef", | ||||||||||||||||||||||||||||
| 24 | lazy => 1, | ||||||||||||||||||||||||||||
| 25 | default => sub { | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 27 | 0 | my @extra; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $self->nodeName_attr ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | push @extra, ""; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else { | ||||||||||||||||||||||||||||
| 32 | 0 | push @extra, undef; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( $self->xmlns_attr ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 35 | 0 | push @extra, ""; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | elsif ( !defined $extra[0] ) { | ||||||||||||||||||||||||||||
| 38 | 0 | pop @extra; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 0 | \@extra; | |||||||||||||||||||||||||||
| 41 | 9 | }; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 9 | ▶ | method node_ok( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=3 SCAR=22.0
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | ( $node->nodeType == XML_TEXT_NODE or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$node->nodeType == 3 or $node->nodeType == 4
MC/DC0%0/2
$node->nodeType == 3 or $node->nodeType == 4
$node->nodeType == 3
$node->nodeType == 4
Truth table0%0/3
A or B
A= $node->nodeType == 3B= $node->nodeType == 4
| |||||||||||||||||||||||||||||
| 45 | $node->nodeType == XML_CDATA_SECTION_NODE ) | ||||||||||||||||||||||||||||
| 46 | ? 1 : undef; | ||||||||||||||||||||||||||||
| 47 | 9 | } | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 9 | ▶ | method accept( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=3 SCAR=23.0
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( $node->nodeType == XML_TEXT_NODE ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 51 | 0 | ($self->attrName, $node->data, @{$self->extra}); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | elsif ( $node->nodeType == XML_CDATA_SECTION_NODE ) { | ||||||||||||||||||||||||||||
| 54 | 0 | ($self->attrName, $node->data, @{$self->extra}); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 0 | $ctx->exception("expected text node", $node); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 9 | } | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 9 | ▶ | method complete( PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 62 | 0 | 1; | |||||||||||||||||||||||||||
| 63 | 9 | } | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 9 | ▶ | method expected( PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 66 | 0 | "TextNode"; | |||||||||||||||||||||||||||
| 67 | 9 | } | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 9 | ▶ | method output ( Object $item, XML::LibXML::Element $node, PRANG::Graph::Context $ctx, Item $value?, Int $slot?, Str $name? ) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=5 SCAR=32.7
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $value //= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$value //= do {
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
}
| |||||||||||||||||||||||||||||
| 71 | 0 | my $attrName = $self->attrName; | |||||||||||||||||||||||||||
| 72 | 0 | $item->$attrName; | |||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( ref $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $value = $value->[$slot]; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return unless length($value//""); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$value // ""
MC/DC0%0/1
$value // ""
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||
| 78 | 0 | my $doc = $node->ownerDocument; | |||||||||||||||||||||||||||
| 79 | 0 | my $tn = $doc->createTextNode($value); | |||||||||||||||||||||||||||
| 80 | 0 | $node->appendChild($tn); | |||||||||||||||||||||||||||
| 81 | 9 | } | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 9 | with 'PRANG::Graph::Node'; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 9 | 1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head1 NAME | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | PRANG::Graph::Text - accept an XML TextNode | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | See L<PRANG::Graph::Meta::Element> source and | ||||||||||||||||||||||||||||
| 96 | L<PRANG::Graph::Node> for examples and information. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | This graph node specifies that the XML graph at this point may contain | ||||||||||||||||||||||||||||
| 101 | a text node. If it doesn't, this is considered equivalent to a | ||||||||||||||||||||||||||||
| 102 | zero-length text node. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | If the element only has only complex children, it will not have one of | ||||||||||||||||||||||||||||
| 105 | these objects in its graph. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Along with L<PRANG::Graph::Element>, this graph node is the only type | ||||||||||||||||||||||||||||
| 108 | which may actually consume input XML nodes or emit them on output. | ||||||||||||||||||||||||||||
| 109 | The other node types merely change the state in the | ||||||||||||||||||||||||||||
| 110 | L<PRANG::Graph::Context> object. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =over | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item B<attrName> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Used when emitting; specifies the method to call to retrieve the item | ||||||||||||||||||||||||||||
| 119 | to be output. Also used when parsing, to return the Moose attribute | ||||||||||||||||||||||||||||
| 120 | slot for construction. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =back | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | L<PRANG::Graph::Meta::Class>, L<PRANG::Graph::Meta::Element>, | ||||||||||||||||||||||||||||
| 127 | L<PRANG::Graph::Context>, L<PRANG::Graph::Node> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 AUTHOR AND LICENCE | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Development commissioned by NZ Registry Services, and carried out by | ||||||||||||||||||||||||||||
| 132 | Catalyst IT - L<http://www.catalyst.net.nz/> | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Copyright 2009, 2010, NZ Registry Services. This module is licensed | ||||||||||||||||||||||||||||
| 135 | under the Artistic License v2.0, which permits relicensing under other | ||||||||||||||||||||||||||||
| 136 | Free Software licenses. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||