| 1 | |||||||||||||||||||||||||||||||||
| 2 | package PRANG::Graph::Quantity; | ||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||
| 7 | 9 | has 'min' => | |||||||||||||||||||||||||||||||
| 8 | is => "ro", | ||||||||||||||||||||||||||||||||
| 9 | isa => "Int", | ||||||||||||||||||||||||||||||||
| 10 | predicate => "has_min", | ||||||||||||||||||||||||||||||||
| 11 | ; | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 9 | has 'max' => | |||||||||||||||||||||||||||||||
| 14 | is => "ro", | ||||||||||||||||||||||||||||||||
| 15 | isa => "Int", | ||||||||||||||||||||||||||||||||
| 16 | predicate => "has_max", | ||||||||||||||||||||||||||||||||
| 17 | ; | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 9 | has 'child' => | |||||||||||||||||||||||||||||||
| 20 | is => "ro", | ||||||||||||||||||||||||||||||||
| 21 | isa => "PRANG::Graph::Node", | ||||||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||||||
| 23 | ; | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 9 | has 'attrName' => | |||||||||||||||||||||||||||||||
| 26 | is => "ro", | ||||||||||||||||||||||||||||||||
| 27 | isa => "Str", | ||||||||||||||||||||||||||||||||
| 28 | required => 1, | ||||||||||||||||||||||||||||||||
| 29 | ; | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub accept_many { 1 } | ||||||||||||||||||||||||||||||
|
Subroutine
accept_many: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | method accept( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=5 SCAR=32.7
| |||||||||||||||||||||||||||||||||
| 34 | 0 | my $found = $ctx->quant_found; | |||||||||||||||||||||||||||||||
| 35 | 0 | my $ok = defined $self->child->node_ok($node, $ctx); | |||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return if not $ok; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my ($key, $value, $x, $ns) = $self->child->accept($node, $ctx) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | or $ctx->exception( | ||||||||||||||||||||||||||||||||
| 39 | "internal error: node ok, but then not accepted?", | ||||||||||||||||||||||||||||||||
| 40 | $node, | ||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||
| 42 | 0 | $found++; | |||||||||||||||||||||||||||||||
| 43 | 0 | $ctx->quant_found($found); | |||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $self->has_max and $found > $self->max ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->has_max and $found > $self->max
MC/DC0%0/2
$self->has_max and $found > $self->max
$self->has_max
$found > $self->max
Truth table0%0/3
A and B
A= $self->has_maxB= $found > $self->max
| |||||||||||||||||||||||||||||||||
| 45 | 0 | $ctx->exception("node appears too many times", $node); | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | 0 | ($key, $value, $x, $ns); | |||||||||||||||||||||||||||||||
| 48 | 9 | } | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 9 | ▶ | method complete( PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=2 SCAR=15.1
| |||||||||||||||||||||||||||||||||
| 51 | 0 | my $found = $ctx->quant_found; | |||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return !( $self->has_min and $found < $self->min ); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->has_min && $found < $self->min
MC/DC0%0/2
$self->has_min && $found < $self->min
$self->has_min
$found < $self->min
Truth table0%0/3
A && B
A= $self->has_minB= $found < $self->min
| |||||||||||||||||||||||||||||||||
| 53 | 9 | } | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 9 | ▶ | method expected( PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=4 SCAR=28.6
| |||||||||||||||||||||||||||||||||
| 56 | 0 | my $desc; | |||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( $self->has_min ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $self->has_max ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | $desc = "between ".$self->min." and ".$self->max; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||||||||||||
| 62 | 0 | $desc = "at least ".$self->min; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( $self->has_max ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 0 | $desc = "optionally up to ".$self->max; | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||||||
| 70 | 0 | $desc = "zero or more"; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | 0 | my @expected = $self->child->expected($ctx); | |||||||||||||||||||||||||||||||
| 74 | 0 | return("($desc of: ", @expected, ")"); | |||||||||||||||||||||||||||||||
| 75 | 9 | } | |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 9 | ▶ | method output ( Object $item, XML::LibXML::Element $node, PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=10 SCAR=46.2
| |||||||||||||||||||||||||||||||||
| 78 | 0 | my $attrName = $self->attrName; | |||||||||||||||||||||||||||||||
| 79 | 0 | my $val = $item->$attrName; | |||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( $self->has_max and $self->max == 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->has_max and $self->max == 1
MC/DC0%0/2
$self->has_max and $self->max == 1
$self->has_max
$self->max == 1
Truth table0%0/3
A and B
A= $self->has_maxB= $self->max == 1
| |||||||||||||||||||||||||||||||||
| 81 | # this is an 'optional'-type thingy | ||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( defined $val ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 0 | $self->child->output($item,$node,$ctx,value => $val); | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||
| 87 | # this is an arrayref-type thingy | ||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ( !$val and !$self->has_min ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$val || $self->has_min
MC/DC0%0/2
$val || $self->has_min
$val
$self->has_min
Truth table0%0/3
A || B
A= $valB= $self->has_min
| |||||||||||||||||||||||||||||||||
| 89 | # ok, that's fine | ||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | ▶ | elsif ( $val and (ref($val)||"") ne "ARRAY" ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/5
$val and (ref $val || "") ne "ARRAY"
ref $val || ''
MC/DC0%0/2
$val and (ref $val || "") ne "ARRAY"
$val
ref $val
Truth table0%0/3
A and B
A= $valB= ref $val
| |||||||||||||||||||||||||||||||||
| 92 | # that's not | ||||||||||||||||||||||||||||||||
| 93 | 0 | die "item $item / slot $attrName is $val, not" | |||||||||||||||||||||||||||||||
| 94 | ."an ArrayRef"; | ||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | for ( my $i = 0; $i <= $#$val; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | 0 | $ctx->quant_found($i+1); | |||||||||||||||||||||||||||||||
| 99 | 0 | $self->child->output( | |||||||||||||||||||||||||||||||
| 100 | $item,$node,$ctx, | ||||||||||||||||||||||||||||||||
| 101 | value => $val->[$i], | ||||||||||||||||||||||||||||||||
| 102 | slot => $i, | ||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | 9 | } | |||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 9 | with 'PRANG::Graph::Node'; | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 9 | 1; | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | PRANG::Graph::Quantity - a bounded quantity of graph nodes | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | See L<PRANG::Graph::Meta::Element> source and | ||||||||||||||||||||||||||||||||
| 122 | L<PRANG::Graph::Node> for examples and information. | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | This graph node specifies that the XML graph at this point has a | ||||||||||||||||||||||||||||||||
| 127 | quantity of text nodes, elements or element choices depending on the | ||||||||||||||||||||||||||||||||
| 128 | type of entries in the B<child> property. | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | If the quantity is always 1, that is, the element is required and may | ||||||||||||||||||||||||||||||||
| 131 | only appear one, then the element does not have one of these objects | ||||||||||||||||||||||||||||||||
| 132 | in their graph. | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | =over | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | =item B<PRANG::Graph::Node child> | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | The B<child> property provides the next portion of the XML Graph. | ||||||||||||||||||||||||||||||||
| 141 | Depending on the type of entry, it will accept and emit nodes in a | ||||||||||||||||||||||||||||||||
| 142 | particular way. | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | Entries must be one of L<PRANG::Graph::Choice>, | ||||||||||||||||||||||||||||||||
| 145 | L<PRANG::Graph::Element>, or L<PRANG::Graph::Text>. | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | =item B<Int min> | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | =item B<Int max> | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | Bounds on the number of times this graph node will match. | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | =item B<attrName> | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | Used when emitting; specifies the method to call to retrieve the item | ||||||||||||||||||||||||||||||||
| 156 | to be output. | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | =back | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | L<PRANG::Graph::Meta::Class>, L<PRANG::Graph::Meta::Element>, | ||||||||||||||||||||||||||||||||
| 163 | L<PRANG::Graph::Context>, L<PRANG::Graph::Node> | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | Lower order L<PRANG::Graph::Node> types: | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | L<PRANG::Graph::Choice>, L<PRANG::Graph::Element>, | ||||||||||||||||||||||||||||||||
| 168 | L<PRANG::Graph::Text> | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | =head1 AUTHOR AND LICENCE | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | Development commissioned by NZ Registry Services, and carried out by | ||||||||||||||||||||||||||||||||
| 173 | Catalyst IT - L<http://www.catalyst.net.nz/> | ||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | Copyright 2009, 2010, NZ Registry Services. This module is licensed | ||||||||||||||||||||||||||||||||
| 176 | under the Artistic License v2.0, which permits relicensing under other | ||||||||||||||||||||||||||||||||
| 177 | Free Software licenses. | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | =cut | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||