| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Fey::ORM::Role::Iterator; |
|
2
|
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
10600
|
use strict; |
|
|
13
|
|
|
|
|
33
|
|
|
|
13
|
|
|
|
|
594
|
|
|
4
|
13
|
|
|
13
|
|
79
|
use warnings; |
|
|
13
|
|
|
|
|
24
|
|
|
|
13
|
|
|
|
|
485
|
|
|
5
|
13
|
|
|
13
|
|
77
|
use namespace::autoclean; |
|
|
13
|
|
|
|
|
25
|
|
|
|
13
|
|
|
|
|
108
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
13
|
|
|
13
|
|
1323
|
use Fey::ORM::Types qw( ArrayRefOfClasses Bool Int ); |
|
|
13
|
|
|
|
|
25
|
|
|
|
13
|
|
|
|
|
124
|
|
|
10
|
13
|
|
|
13
|
|
105658
|
use List::AllUtils qw( pairwise ); |
|
|
13
|
|
|
|
|
13933
|
|
|
|
13
|
|
|
|
|
1150
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
13
|
|
|
13
|
|
89
|
use Moose::Role; |
|
|
13
|
|
|
|
|
23
|
|
|
|
13
|
|
|
|
|
137
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
requires qw( _get_next_result reset ); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has classes => ( |
|
17
|
|
|
|
|
|
|
is => 'ro', |
|
18
|
|
|
|
|
|
|
isa => ArrayRefOfClasses, |
|
19
|
|
|
|
|
|
|
coerce => 1, |
|
20
|
|
|
|
|
|
|
required => 1, |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has index => ( |
|
24
|
|
|
|
|
|
|
traits => ['Counter'], |
|
25
|
|
|
|
|
|
|
is => 'ro', |
|
26
|
|
|
|
|
|
|
isa => Int, |
|
27
|
|
|
|
|
|
|
default => 0, |
|
28
|
|
|
|
|
|
|
init_arg => undef, |
|
29
|
|
|
|
|
|
|
handles => { |
|
30
|
|
|
|
|
|
|
_inc_index => 'inc', |
|
31
|
|
|
|
|
|
|
_reset_index => 'reset', |
|
32
|
|
|
|
|
|
|
}, |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has _can_make_hashes => ( |
|
36
|
|
|
|
|
|
|
is => 'ro', |
|
37
|
|
|
|
|
|
|
isa => Bool, |
|
38
|
|
|
|
|
|
|
lazy => 1, |
|
39
|
|
|
|
|
|
|
init_arg => undef, |
|
40
|
|
|
|
|
|
|
default => sub { |
|
41
|
|
|
|
|
|
|
List::AllUtils::all { $_->can('Table') } @{ $_[0]->classes() }; |
|
42
|
|
|
|
|
|
|
}, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitBuiltinHomonyms) |
|
46
|
|
|
|
|
|
|
sub next { |
|
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $result = $self->_get_next_result(); |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
return unless $result; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$self->_inc_index(); |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
return wantarray ? @{$result} : $result->[0]; |
|
|
0
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
## use critic |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub next_as_hash { |
|
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
die 'Cannot make a hash unless all classes have a Table() method' |
|
63
|
|
|
|
|
|
|
unless $self->_can_make_hashes(); |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my @result = $self->next(); |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
return unless @result; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
|
|
return pairwise { $a->Table()->name() => $b } @{ $self->classes() }, |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
@result; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub all { |
|
74
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
$self->reset() if $self->index(); |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $self->remaining(); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub all_as_hashes { |
|
82
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$self->reset() if $self->index(); |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return $self->remaining_as_hashes(); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub remaining { |
|
90
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my @result; |
|
93
|
0
|
|
|
|
|
|
while ( my @r = $self->next() ) { |
|
94
|
0
|
0
|
|
|
|
|
push @result, @r == 1 ? @r : \@r; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return @result; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub remaining_as_hashes { |
|
101
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my @result; |
|
104
|
0
|
|
|
|
|
|
while ( my %r = $self->next_as_hash() ) { |
|
105
|
0
|
|
|
|
|
|
push @result, \%r; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return @result; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# ABSTRACT: A role for things that iterate over Fey::Object::Table objects |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=pod |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 NAME |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Fey::ORM::Role::Iterator - A role for things that iterate over Fey::Object::Table objects |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 VERSION |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
version 0.47 |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
package My::Iterator; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
use Moose; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
with 'Fey::ORM::Role::Iterator'; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This role provides some common methods used by |
|
138
|
|
|
|
|
|
|
C<Fey::Object::Iterator> classes, as well as defining a consistent |
|
139
|
|
|
|
|
|
|
interface for iterators. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 REQUIRED METHODS |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Classes which consume this role must provide C<_get_next_result()> and |
|
144
|
|
|
|
|
|
|
C<reset()> methods. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 PROVIDED ATTRIBUTES |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This role provides the following attributes. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 $iterator->classes() |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
An array reference of class names. Each class must be a subclass of |
|
153
|
|
|
|
|
|
|
L<Fey::Object::Table>. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 $iterator->index() |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The current iterator index. Also provides C<_inc_index()> and |
|
158
|
|
|
|
|
|
|
C<_reset_index()> methods. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This role provides the following methods. These methods are documented |
|
163
|
|
|
|
|
|
|
in L<Fey::Object::Iterator::FromSelect>. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 $iterator->next |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 $iterator->next_as_hash() |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 $iterator->all() |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 $iterator->all_as_hashes() |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 $iterator->remaining() |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 $iterator->remaining_as_hashes() |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 AUTHOR |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This software is copyright (c) 2011 - 2015 by Dave Rolsky. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
186
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |