PRANG/Graph/Seq.pm

filter: Statementstmt 94.0% 47 / 50 Branchbran 87.5% 14 / 16 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 4 totaltotal 88.5% 77 / 87 SCAR 24.9
CC
12
Cov
93%
accept
6.0
complete
5.0
expected
2.0
CRAP 12.0
« PRANG/Graph/Text.pm ↑ Summary PRANG/Util.pm »
1  
2 package PRANG::Graph::Seq;
3 11 $PRANG::Graph::Seq::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  
7 has 'members' =>
8 is => "ro",
9 isa => "ArrayRef[PRANG::Graph::Node]",
10 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
11 11 ;
12  
13 sub accept {
14 239 ▶ my $self = shift;
Subroutine accept: called CC=6 SCAR=17.9
Pod undocumented
15 239 my ( $node, $ctx, $lax ) = pos_validated_list(
16 \@_,
17 { isa => 'XML::LibXML::Node' },
18 { isa => 'PRANG::Graph::Context' },
19 { isa => 'Bool' },
20 );
21
22 239 my $pos = $ctx->seq_pos;
23 239 my ($key, $val, $x, $ns, $member);
24 239 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$key or do { do { $member = $self->members->[$pos - 1]; unless ($member) { $ctx->exception("unexpected element", $node) unless $lax; return; } ; () = $member->accept($node, $ctx, $lax); unless ($key and $member->accept_many) { $ctx->seq_pos(++$pos); } } } 268 217 485
25 507 $member = $self->members->[$pos-1];
26
27 507 ▶ if (! $member) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($member) 7 500 507
28 7 ▶ $ctx->exception("unexpected element", $node)
Branch: 1 branch
BranchTrueFalseTotal
unless $lax 4 3 7
29 unless $lax;
30 3 return;
31 }
32
33 500 ($key, $val, $x, $ns) = $member->accept($node, $ctx, $lax);
34
35 485 ▶ if (!$key or !$member->accept_many ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key and $member->accept_many) 356 129 485
Condition100%3/3
$key and $member->accept_many
!ll&&!rl&&r
26888129
MC/DC100%2/2
$key and $member->accept_many
$key $member->accept_many
Truth table100%3/3
A and B
A= $keyB= $member->accept_many
ABresult
0X0
100
111
36 356 $ctx->seq_pos(++$pos);
37 }
38 } until ($key);
39 217 ($key, $val, $x, $ns);
40 }
41  
42 sub complete {
43 93 ▶ my $self = shift;
Subroutine complete: called CC=5 SCAR=16.1
Pod undocumented
44 93 my ( $ctx ) = pos_validated_list(
45 \@_,
46 { isa => 'PRANG::Graph::Context' },
47 );
48
49 93 my $pos = $ctx->seq_pos;
50 93 my $member;
51 my $done;
52 93 ▶ while ( !$done ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 435 93 528
53 435 $member = $self->members->[$pos-1];
54 435 ▶ if ( $member and $member->complete($ctx) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member and $member->complete($ctx)) { } 342 93 435
Condition100%3/3
$member and $member->complete($ctx)
!ll&&!rl&&r
912342
MC/DC100%2/2
$member and $member->complete($ctx)
$member $member->complete($ctx)
Truth table100%3/3
A and B
A= $memberB= $member->complete($ctx)
ABresult
0X0
100
111
55 342 $ctx->seq_pos(++$pos);
56 }
57 else {
58 93 $done = 1;
59 }
60 }
61 93 my $cmp = $pos-1 <=> @{$self->members};
62 93 ▶ if ( $cmp == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp == 1) 0 93 93
63 0 warn "Accepted too much!!";
64 }
65 93 return ( $cmp != -1 );
66 }
67  
68 sub expected {
69 2 ▶ my $self = shift;
Subroutine expected: called CC=2 SCAR=7.1
Pod undocumented
70 2 my ( $ctx ) = pos_validated_list(
71 \@_,
72 { isa => 'PRANG::Graph::Context' },
73 );
74
75 2 my $pos = $ctx->seq_pos;
76 2 my $member = $self->members->[$pos-1];
77 2 ▶ if ($member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member) { } 2 0 2
78 2 return $member->expected($ctx);
79 }
80 else {
81 0 return "er... nothing?";
82 }
83 }
84  
85 sub output {
86 46 ▶ my $self = shift;
Subroutine output: called CC=2 SCAR=6.9
Pod undocumented
87 46 my ( $item, $node, $ctx ) = pos_validated_list(
88 \@_,
89 { isa => 'Item' },
90 { isa => 'XML::LibXML::Element' },
91 { isa => 'PRANG::Graph::Context' },
92 );
93
94 46 for my $member ( @{ $self->members } ) {
95 280 $member->output($item,$node,$ctx);
96 }
97 }
98  
99 11 with 'PRANG::Graph::Node';
100  
101 11 1;
102  
103 __END__
104  
105 =head1 NAME
106  
107 PRANG::Graph::Seq - a sequence of graph nodes
108  
109 =head1 SYNOPSIS
110  
111 See L<PRANG::Graph::Meta::Element> source and
112 L<PRANG::Graph::Node> for examples and information.
113  
114 =head1 DESCRIPTION
115  
116 This graph node specifies that the XML graph at this point has a
117 sequence of text nodes, elements, element choices or quantities
118 thereof, depending on the type of entries in the B<members> property.
119  
120 Classes with only one element defined do not have one of these objects
121 in their graph. Typically there is one members entry per element
122 defined in the class.
123  
124 =head1 ATTRIBUTES
125  
126 =over
127  
128 =item B<ArrayRef[PRANG::Graph::Node] members>
129  
130 The B<members> property provides the next portion of the XML Graph.
131 Depending on the type of entry, it will accept and emit nodes in a
132 particular way.
133  
134 Entries must be one of L<PRANG::Graph::Quant>, L<PRANG::Graph::Choice>,
135 L<PRANG::Graph::Element>, or L<PRANG::Graph::Text>.
136  
137 =back
138  
139 =head1 SEE ALSO
140  
141 L<PRANG::Graph::Meta::Class>, L<PRANG::Graph::Meta::Element>,
142 L<PRANG::Graph::Context>, L<PRANG::Graph::Node>
143  
144 Lower order L<PRANG::Graph::Node> types:
145  
146 L<PRANG::Graph::Quant>, L<PRANG::Graph::Choice>,
147 L<PRANG::Graph::Element>, L<PRANG::Graph::Text>
148  
149 =head1 AUTHOR AND LICENCE
150  
151 Development commissioned by NZ Registry Services, and carried out by
152 Catalyst IT - L<http://www.catalyst.net.nz/>
153  
154 Copyright 2009, 2010, NZ Registry Services. This module is licensed
155 under the Artistic License v2.0, which permits relicensing under other
156 Free Software licenses.
157  
158 =cut
159  
« PRANG/Graph/Text.pm ↑ Summary PRANG/Util.pm »