Iterator::BreakOn - Iterator with control flow breaks


Iterator-BreakOn documentation  | view source Contained in the Iterator-BreakOn distribution.

Index


NAME

Top

Iterator::BreakOn - Iterator with control flow breaks

SYNOPSIS

Top

    use Iterator::BreakOn;

    #
    #   get a generic data source with a next method implemented whom
    #   returns a generic object 
    #
    #   in this example the order of the items in the data stream is assumed
    #   to be:
    #       location, zipcode, name
    #
    my $datasource = $myschema->resultset('mytable')->search();

    my $iter = Iterator::BreakOn->new( 
                    datasource => $datasource,
                    break_before => [ 
                            qw(location) 
                            ],
                    break_after => [ 
                            'location'  =>  \&after_location,
                            'zipcode' 
                            ],
                    on_last_item    =>  sub { print "Finnished !"; },
                    );

    #                    
    # There are three uses modes:
    #
    #   Fully automatic mode: useless if not defined code for breaks
    $iter->run();

    #   Semi-automatic mode: get only the item (run automatically the other
    #   events)
    while (my $data_item = $iter->next()) {
        # do something with data ...
        1;
    }

    #   Manual mode: get every event as an object
    while (my $event = $iter->next_event()) {
        if ($event->name() eq 'before_location') {
            # do something before a new location comes

        }
        elsif ($event->name() eq 'after_zipcode')) {
            # do something after the last zipcode reached

        }
        elsif ($event->name() eq 'next_item' ) {
            # get the item (including the first and last items)
            my $data = $iter->next();

            # and do something whit him

        }
        elsif ($event->name() eq 'last_item') {
            # and do something when the end of data reached

        }
    } # end while

DESCRIPTION

Top

Events order

Whatever the run mode this is the order of the events:

* on_first

Event raise before the first item.

* before_XXXX

Multiple event raise before the XXXX field change his value in the next item.

* on_every

Raise for each item.

* after_XXXX

Multiple event raise after the XXXX field change his value in the next item. The order is deep first.

* on_last

Raise after the last item.

INTERFACE

Top

This module inherits from Iterator::BreakOn::Base. See this module for detailed documentation about methods.

DIAGNOSTICS

Top

The package uses the Exception::Class library for error management. See Iterator::BreakOn::X for the list of exceptions.

CONFIGURATION AND ENVIRONMENT

Top

Iterator::BreakOn requires no configuration files or environment variables.

DEPENDENCIES

Top

The module needs the following Perl modules:

Class::Accessor
Exception::Class
Test::More
Text::CSV

INCOMPATIBILITIES

Top

None reported.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests to the author.

AUTHOR

Top

Víctor Moral <victor@taquiones.net>

LICENSE AND COPYRIGHT

Top

DISCLAIMER OF WARRANTY

Top

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


Iterator-BreakOn documentation  | view source Contained in the Iterator-BreakOn distribution.