File Coverage

blib/lib/PRANG/Graph/Seq.pm
Criterion Covered Total %
statement 6 45 13.3
branch 0 12 0.0
condition 0 6 0.0
subroutine 2 6 33.3
pod 0 4 0.0
total 8 73 10.9


line stmt bran cond sub pod time code
1              
2             package PRANG::Graph::Seq;
3             $PRANG::Graph::Seq::VERSION = '0.19';
4 1     1   1842 use Moose;
  1         2  
  1         7  
5 1     1   6060 use MooseX::Params::Validate;
  1         2  
  1         9  
6              
7             has 'members' =>
8             is => "ro",
9             isa => "ArrayRef[PRANG::Graph::Node]",
10             default => sub { [] },
11             ;
12              
13             sub accept {
14 0     0 0   my $self = shift;
15 0           my ( $node, $ctx, $lax ) = pos_validated_list(
16             \@_,
17             { isa => 'XML::LibXML::Node' },
18             { isa => 'PRANG::Graph::Context' },
19             { isa => 'Bool' },
20             );
21            
22 0           my $pos = $ctx->seq_pos;
23 0           my ($key, $val, $x, $ns, $member);
24 0           do {
25 0           $member = $self->members->[$pos-1];
26            
27 0 0         if (! $member) {
28 0 0         $ctx->exception("unexpected element", $node)
29             unless $lax;
30 0           return;
31             }
32            
33 0           ($key, $val, $x, $ns) = $member->accept($node, $ctx, $lax);
34            
35 0 0 0       if (!$key or !$member->accept_many ) {
36 0           $ctx->seq_pos(++$pos);
37             }
38             } until ($key);
39 0           ($key, $val, $x, $ns);
40             }
41              
42             sub complete {
43 0     0 0   my $self = shift;
44 0           my ( $ctx ) = pos_validated_list(
45             \@_,
46             { isa => 'PRANG::Graph::Context' },
47             );
48            
49 0           my $pos = $ctx->seq_pos;
50 0           my $member;
51             my $done;
52 0           while ( !$done ) {
53 0           $member = $self->members->[$pos-1];
54 0 0 0       if ( $member and $member->complete($ctx) ) {
55 0           $ctx->seq_pos(++$pos);
56             }
57             else {
58 0           $done = 1;
59             }
60             }
61 0           my $cmp = $pos-1 <=> @{$self->members};
  0            
62 0 0         if ( $cmp == 1 ) {
63 0           warn "Accepted too much!!";
64             }
65 0           return ( $cmp != -1 );
66             }
67              
68             sub expected {
69 0     0 0   my $self = shift;
70 0           my ( $ctx ) = pos_validated_list(
71             \@_,
72             { isa => 'PRANG::Graph::Context' },
73             );
74            
75 0           my $pos = $ctx->seq_pos;
76 0           my $member = $self->members->[$pos-1];
77 0 0         if ($member) {
78 0           return $member->expected($ctx);
79             }
80             else {
81 0           return "er... nothing?";
82             }
83             }
84              
85             sub output {
86 0     0 0   my $self = shift;
87 0           my ( $item, $node, $ctx ) = pos_validated_list(
88             \@_,
89             { isa => 'Item' },
90             { isa => 'XML::LibXML::Element' },
91             { isa => 'PRANG::Graph::Context' },
92             );
93            
94 0           for my $member ( @{ $self->members } ) {
  0            
95 0           $member->output($item,$node,$ctx);
96             }
97             }
98              
99             with 'PRANG::Graph::Node';
100              
101             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