• Publicidad

Nuevo módulo Iterator::BreakOn

Aquí encontrarás todo lo que sea específicamente acerca de módulos de Perl. Ya sea que estás compartiendo tu módulo, un manual o simplemente tienes una duda acerca de alguno.

Nuevo módulo Iterator::BreakOn

Notapor explorer » 2007-04-26 09:30 @437

Nuestro amigo Victor Moral ha subido a CPAN su nuevo módulo Iterator::BreakOn.

Esperamos que os sea útil para vuestros nuevos programas.

NAME

Iterator::BreakOn - Iterator with control flow breaks

SYNOPSIS
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
    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
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Publicidad

Volver a Módulos

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 4 invitados

cron