File Coverage

blib/lib/CPS/Governor/Simple.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 17 17 100.0


line stmt bran cond sub pod time code
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     17   23786 use strict;
  17         60  
  17         563  
9 17     17   85 use warnings;
  17         31  
  17         506  
10              
11 17     17   91 use base qw( CPS::Governor );
  17         33  
  17         10159  
12              
13             our $VERSION = '0.18';
14              
15             =head1 NAME
16              
17             C - 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 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.
44              
45             =cut
46              
47             sub again
48             {
49 101     101 1 1733 my $self = shift;
50 101         120 my $code = shift;
51              
52 101         275 goto &$code; # intentionally leave @_ alone
53             }
54              
55             =head1 AUTHOR
56              
57             Paul Evans
58              
59             =cut
60              
61             0x55AA;