line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UR::Object::Iterator; |
2
|
|
|
|
|
|
|
|
3
|
266
|
|
|
266
|
|
1000
|
use strict; |
|
266
|
|
|
|
|
311
|
|
|
266
|
|
|
|
|
6554
|
|
4
|
266
|
|
|
266
|
|
862
|
use warnings; |
|
266
|
|
|
|
|
340
|
|
|
266
|
|
|
|
|
33923
|
|
5
|
|
|
|
|
|
|
require UR; |
6
|
|
|
|
|
|
|
require UR::Iterator; |
7
|
|
|
|
|
|
|
our $VERSION = "0.46"; # UR $VERSION; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @CARP_NOT = qw( UR::Object ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw( UR::Iterator ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# These are no longer UR Objects. They're regular blessed references that |
14
|
|
|
|
|
|
|
# get garbage collected in the regular ways |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub create_for_filter_rule { |
17
|
70
|
|
|
70
|
1
|
122
|
my $class = shift; |
18
|
70
|
|
|
|
|
100
|
my $filter_rule = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
70
|
|
|
|
|
232
|
my $code = $UR::Context::current->get_objects_for_class_and_rule($filter_rule->subject_class_name,$filter_rule,undef,1); |
22
|
|
|
|
|
|
|
|
23
|
70
|
|
|
|
|
253
|
my $self = bless { filter_rule_id => $filter_rule->id, |
24
|
|
|
|
|
|
|
_iteration_closure => $code}, |
25
|
|
|
|
|
|
|
__PACKAGE__; |
26
|
70
|
|
|
|
|
209
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=pod |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
UR::Object::Iterator - API for iterating through objects matching a rule |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $rule = UR::BoolExpr->resolve('Some::Class', foo => 1); |
40
|
|
|
|
|
|
|
my $iter = UR::Object::Iterator->create_for_filter_rule($rule); |
41
|
|
|
|
|
|
|
while (my $obj = $iter->next()) { |
42
|
|
|
|
|
|
|
print "Got an object: ",$obj->id,"\n"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Equivalent |
46
|
|
|
|
|
|
|
my $iter2 = Some::Class->create_iterator(foo => 1); |
47
|
|
|
|
|
|
|
while (my $obj = $iter2->next()) { |
48
|
|
|
|
|
|
|
print "Got an object: ",$obj->id,"\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
get(), implemented in UR::Object, is the usual way for retrieving sets of |
54
|
|
|
|
|
|
|
objects matching particular properties. When the result set of data is |
55
|
|
|
|
|
|
|
large, it is often more efficient to use an iterator to access the data |
56
|
|
|
|
|
|
|
instead of getting it all in one list. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
UR::Object implements create_iterator(), which is just a wrapper around |
59
|
|
|
|
|
|
|
create_for_filter_rule(). |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
UR::Object::Iterator instances are normal Perl object references, not |
62
|
|
|
|
|
|
|
UR-based objects. They do not live in the Context's object cache, and |
63
|
|
|
|
|
|
|
obey the normal Perl rules about scoping. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over 4 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item create_for_filter_rule |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$iter = UR::Object::Iterator->create_for_filter_rule($boolexpr); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Creates an iterator object based on the given BoolExpr (rule). Under the |
74
|
|
|
|
|
|
|
hood, it calls get_objects_for_class_and_rule() on the current Context |
75
|
|
|
|
|
|
|
with the $return_closure flag set to true. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=back |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 Methods inherited from UR::Iterator |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over 4 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item next |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item map |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item peek |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item remaining |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L, L, L |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |