Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

Iterator::BreakOn
Iterator with control flow breaks

Iterator::BreakOn - Iterator with control flow breaks


NAME

Iterator::BreakOn - Iterator with control flow breaks


SYNOPSIS


    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

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

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


DIAGNOSTICS

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


CONFIGURATION AND ENVIRONMENT

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


DEPENDENCIES

The module needs the following Perl modules:

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


INCOMPATIBILITIES

None reported.


BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to the author.


AUTHOR

Víctor Moral <victor@taquiones.net>


LICENSE AND COPYRIGHT

Copyright (C) 2007 <Victor Moral>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


DISCLAIMER OF WARRANTY

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.

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy