line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LDAP::Class::SimpleIterator; |
2
|
10
|
|
|
10
|
|
32
|
use strict; |
|
10
|
|
|
|
|
8
|
|
|
10
|
|
|
|
|
239
|
|
3
|
10
|
|
|
10
|
|
31
|
use warnings; |
|
10
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
190
|
|
4
|
10
|
|
|
10
|
|
30
|
use base qw( Rose::Object ); |
|
10
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
561
|
|
5
|
10
|
|
|
10
|
|
33
|
use Carp; |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
402
|
|
6
|
10
|
|
|
10
|
|
45
|
use Data::Dump qw( dump ); |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
378
|
|
7
|
10
|
|
|
10
|
|
34
|
use Net::LDAP::Class::MethodMaker ( 'scalar' => [qw( code )], ); |
|
10
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
49
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.27'; |
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
|
56
|
my $self = shift; |
38
|
7
|
|
|
|
|
34
|
$self->SUPER::init(@_); |
39
|
7
|
50
|
|
|
|
77
|
if ( !defined $self->code ) { |
40
|
0
|
|
|
|
|
0
|
croak "code ref required"; |
41
|
|
|
|
|
|
|
} |
42
|
7
|
|
|
|
|
32
|
$self->{_count} = 0; |
43
|
7
|
|
|
|
|
9
|
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
|
855
|
my $self = shift; |
60
|
29
|
50
|
|
|
|
72
|
return undef if !exists $self->{code}; |
61
|
29
|
|
|
|
|
93
|
my $ret = $self->{code}->(); |
62
|
29
|
100
|
|
|
|
87
|
if ( defined $ret ) { |
63
|
23
|
|
|
|
|
49
|
$self->{_count}++; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
6
|
|
|
|
|
21
|
$self->finish; |
67
|
|
|
|
|
|
|
} |
68
|
29
|
|
|
|
|
97
|
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
|
4
|
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
|
10
|
my $self = shift; |
87
|
7
|
|
|
|
|
48
|
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
|
37
|
my $self = shift; |
100
|
27
|
100
|
|
|
|
94
|
return exists $self->{code} ? 0 : 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub DESTROY { |
104
|
7
|
|
|
7
|
|
976
|
my $self = shift; |
105
|
7
|
50
|
|
|
|
88
|
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__ |