line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Prophet::Collection; |
2
|
1
|
|
|
1
|
|
918
|
use Any::Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
377
|
use Params::Validate; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
4
|
1
|
|
|
1
|
|
4
|
use Prophet::Record; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use overload '@{}' => sub { shift->items }, fallback => 1; |
|
1
|
|
|
0
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
|
0
|
|
|
|
|
0
|
|
7
|
1
|
|
|
1
|
|
64
|
use constant record_class => 'Prophet::Record'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
285
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has app_handle => ( |
10
|
|
|
|
|
|
|
is => 'rw', |
11
|
|
|
|
|
|
|
isa => 'Prophet::App|Undef', |
12
|
|
|
|
|
|
|
required => 0, |
13
|
|
|
|
|
|
|
trigger => sub { |
14
|
|
|
|
|
|
|
my ($self, $app) = @_; |
15
|
|
|
|
|
|
|
$self->handle($app->handle); |
16
|
|
|
|
|
|
|
}, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has handle => ( |
20
|
|
|
|
|
|
|
is => 'rw', |
21
|
|
|
|
|
|
|
isa => 'Prophet::Replica', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has type => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
isa => 'Str', |
27
|
|
|
|
|
|
|
lazy => 1, |
28
|
|
|
|
|
|
|
default => sub { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
$self->record_class->new(app_handle => $self->app_handle)->record_type; |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has items => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => 'ArrayRef', |
37
|
|
|
|
|
|
|
default => sub { [] }, |
38
|
|
|
|
|
|
|
auto_deref => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
1
|
|
sub count { scalar @{ $_[0]->items } } |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add_item { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
push @{ $self->items }, @_; |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Prophet::Collection |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This class allows the programmer to search for L |
54
|
|
|
|
|
|
|
objects matching certain criteria and to operate on those records |
55
|
|
|
|
|
|
|
as a collection. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 new { handle => L, type => $TYPE } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Instantiate a new, empty L object to find items of type |
62
|
|
|
|
|
|
|
C<$TYPE>. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 matching $CODEREF |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Find all Ls of this collection's C where $CODEREF |
67
|
|
|
|
|
|
|
returns true. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub matching { |
72
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
my $coderef = shift; |
74
|
|
|
|
|
|
|
# return undef unless $self->handle->type_exists( type => $self->type ); |
75
|
|
|
|
|
|
|
# find all items, |
76
|
0
|
0
|
|
|
|
|
Carp::cluck unless defined $self->type; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $records = $self->handle->list_records( record_class => $self->record_class, type => $self->type ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# run coderef against each item; |
81
|
|
|
|
|
|
|
# if it matches, add it to items |
82
|
0
|
|
|
|
|
|
for my $record (@$records) { |
83
|
0
|
0
|
|
|
|
|
$self->add_item($record) if ( $coderef->($record) ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# XXX TODO return a count of items found |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 items |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns a reference to an array of all the items found |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 add_item |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 count |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
101
|
1
|
|
|
1
|
|
4
|
no Any::Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |