| 1 | # You may distribute under the terms of either the GNU General Public License | ||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||
| 3 | # | ||
| 4 | # (C) Paul Evans, 2009 -- leonerd@leonerd.org.uk | ||
| 5 | |||
| 6 | package CPS::Governor::Simple; | ||
| 7 | |||
| 8 | 17 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 17 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 17 | ▶ | use base qw( CPS::Governor ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 17 | our $VERSION = '0.18'; | |
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | C<CPS::Governor::Simple> - iterate immediately as fast as possible | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | use CPS qw( gkforeach ); | ||
| 22 | use CPS::Governor::Simple; | ||
| 23 | |||
| 24 | my $gov = CPS::Governor::Simple->new; | ||
| 25 | |||
| 26 | gkforeach( $gov, [ 1 .. 10 ], | ||
| 27 | sub { | ||
| 28 | my ( $item, $knext ) = @_; | ||
| 29 | |||
| 30 | print "$item\n"; | ||
| 31 | goto &$knext; | ||
| 32 | }, | ||
| 33 | sub {}, | ||
| 34 | ); | ||
| 35 | |||
| 36 | =head1 DESCRIPTION | ||
| 37 | |||
| 38 | This L<CPS::Governor> allows the functions using it to run as fast as | ||
| 39 | possible. It invokes its continuations immediately using a tailcall, so as not | ||
| 40 | to let the stack grow arbitrarily. | ||
| 41 | |||
| 42 | Its constructor takes no special arguments, and it provides no other methods | ||
| 43 | beyond those of C<CPS::Governor>. | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | sub again | ||
| 48 | { | ||
| 49 | 101 | ▶ | my $self = shift; |
|
Subroutine
again: called CC=1 SCAR=0.0
Pod
documented
| |||
| 50 | 101 | my $code = shift; | |
| 51 | |||
| 52 | 101 | goto &$code; # intentionally leave @_ alone | |
| 53 | } | ||
| 54 | |||
| 55 | =head1 AUTHOR | ||
| 56 | |||
| 57 | Paul Evans <leonerd@leonerd.org.uk> | ||
| 58 | |||
| 59 | =cut | ||
| 60 | |||
| 61 | 17 | 0x55AA; | |