line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LDAP::Class::SimpleIterator; |
2
|
10
|
|
|
10
|
|
59
|
use strict; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
499
|
|
3
|
10
|
|
|
10
|
|
60
|
use warnings; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
338
|
|
4
|
10
|
|
|
10
|
|
63
|
use base qw( Rose::Object ); |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
917
|
|
5
|
10
|
|
|
10
|
|
61
|
use Carp; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
3041
|
|
6
|
10
|
|
|
10
|
|
66
|
use Data::Dump qw( dump ); |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
611
|
|
7
|
10
|
|
|
10
|
|
60
|
use Net::LDAP::Class::MethodMaker ( 'scalar' => [qw( code )], ); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
90
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.26'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Net::LDAP::Class::SimpleIterator - iterate over Net::LDAP::Class objects |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $iterator = $user->groups_iterator; |
18
|
|
|
|
|
|
|
while ( my $group = $iterator->next ) { |
19
|
|
|
|
|
|
|
# $group isa Net::LDAP::Class::Group |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
printf("%d groups found\n", $iterator->count); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Net::LDAP::Class::SimpleIterator uses a closure (CODE reference) |
26
|
|
|
|
|
|
|
to implement a simple next()-based API. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 init |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Implements the standard object initialization. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub init { |
37
|
7
|
|
|
7
|
1
|
114
|
my $self = shift; |
38
|
7
|
|
|
|
|
54
|
$self->SUPER::init(@_); |
39
|
7
|
50
|
|
|
|
1084132
|
if ( !defined $self->code ) { |
40
|
0
|
|
|
|
|
0
|
croak "code ref required"; |
41
|
|
|
|
|
|
|
} |
42
|
7
|
|
|
|
|
82
|
$self->{_count} = 0; |
43
|
7
|
|
|
|
|
31
|
return $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 code(I) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Required in new(). I is called on every invocation |
49
|
|
|
|
|
|
|
of next(). |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 next |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Calls code() and returns its value, incrementing count() if the value |
54
|
|
|
|
|
|
|
is defined. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub next { |
59
|
29
|
|
|
29
|
1
|
1885
|
my $self = shift; |
60
|
29
|
50
|
|
|
|
224
|
return undef if !exists $self->{code}; |
61
|
29
|
|
|
|
|
341
|
my $ret = $self->{code}->(); |
62
|
29
|
100
|
|
|
|
165
|
if ( defined $ret ) { |
63
|
23
|
|
|
|
|
106
|
$self->{_count}++; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
6
|
|
|
|
|
28
|
$self->finish; |
67
|
|
|
|
|
|
|
} |
68
|
29
|
|
|
|
|
168
|
return $ret; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 count |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns the number of iterations of next() that returned defined. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
1
|
1
|
7
|
sub count { return shift->{_count} } |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 finish |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Deletes the internal code reference. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub finish { |
86
|
7
|
|
|
7
|
1
|
17
|
my $self = shift; |
87
|
7
|
|
|
|
|
75
|
delete $self->{code}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 is_exhausted |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Tests for the existence of the internal code reference, returning |
93
|
|
|
|
|
|
|
true if the internal code reference no longer exists and false |
94
|
|
|
|
|
|
|
if it does. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub is_exhausted { |
99
|
27
|
|
|
27
|
1
|
68
|
my $self = shift; |
100
|
27
|
100
|
|
|
|
204
|
return exists $self->{code} ? 0 : 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub DESTROY { |
104
|
7
|
|
|
7
|
|
2402
|
my $self = shift; |
105
|
7
|
50
|
|
|
|
130
|
if ( defined $self->{code} ) { |
106
|
0
|
|
|
|
|
|
carp("non-exhausted iterator DESTROY'd"); |
107
|
0
|
|
|
|
|
|
Data::Dump::dump($self); |
108
|
0
|
|
|
|
|
|
$self->finish; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |