Net::LDAP::Class::SimpleIterator - iterate over Net::LDAP::Class objects


Net-LDAP-Class documentation Contained in the Net-LDAP-Class distribution.

Index


Code Index:

NAME

Top

Net::LDAP::Class::SimpleIterator - iterate over Net::LDAP::Class objects

SYNOPSIS

Top

 my $iterator = $user->groups_iterator;
 while ( my $group = $iterator->next ) {
    # $group isa Net::LDAP::Class::Group
 }
 printf("%d groups found\n", $iterator->count);

DESCRIPTION

Top

Net::LDAP::Class::SimpleIterator uses a closure (CODE reference) to implement a simple next()-based API.

METHODS

Top

init

Implements the standard object initialization.

code(sub_ref)

Required in new(). sub_ref is called on every invocation of next().

next

Calls code() and returns its value, incrementing count() if the value is defined.

count

Returns the number of iterations of next() that returned defined.

finish

Deletes the internal code reference.

is_exhausted

Tests for the existence of the internal code reference, returning true if the internal code reference no longer exists and false if it does.

AUTHOR

Top

Peter Karman, <karman at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-net-ldap-class at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-LDAP-Class. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Net::LDAP::Class

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Net-LDAP-Class

* CPAN Ratings

http://cpanratings.perl.org/d/Net-LDAP-Class

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-LDAP-Class

* Search CPAN

http://search.cpan.org/dist/Net-LDAP-Class

COPYRIGHT

Top

SEE ALSO

Top

Net::LDAP, Net::LDAP::Batch


Net-LDAP-Class documentation Contained in the Net-LDAP-Class distribution.
package Net::LDAP::Class::SimpleIterator;
use strict;
use warnings;
use base qw( Rose::Object );
use Carp;
use Data::Dump qw( dump );
use Net::LDAP::Class::MethodMaker ( 'scalar' => [qw( code )], );

our $VERSION = '0.26';

sub init {
    my $self = shift;
    $self->SUPER::init(@_);
    if ( !defined $self->code ) {
        croak "code ref required";
    }
    $self->{_count} = 0;
    return $self;
}

sub next {
    my $self = shift;
    return undef if !exists $self->{code};
    my $ret = $self->{code}->();
    if ( defined $ret ) {
        $self->{_count}++;
    }
    else {
        $self->finish;
    }
    return $ret;
}

sub count { return shift->{_count} }

sub finish {
    my $self = shift;
    delete $self->{code};
}

sub is_exhausted {
    my $self = shift;
    return exists $self->{code} ? 0 : 1;
}

sub DESTROY {
    my $self = shift;
    if ( defined $self->{code} ) {
        carp("non-exhausted iterator DESTROY'd");
        Data::Dump::dump($self);
        $self->finish;
    }
}

1;

__END__