Esperamos que os sea útil para vuestros nuevos programas.
NAME
Iterator::BreakOn - Iterator with control flow breaks
SYNOPSIS
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
#
# 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.004 segundos, usando GeSHi 1.0.8.4