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   53159 use strict;
  17         34  
  17         384  
9 17     17   65 use warnings;
  17         25  
  17         377  
10              
11 17     17   79 use base qw( CPS::Governor );
  17         24  
  17         6251  
12              
13             our $VERSION = '0.19';
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 1291 my $self = shift;
50 101         106 my $code = shift;
51              
52 101         186 goto &$code; # intentionally leave @_ alone
53             }
54              
55             =head1 AUTHOR
56              
57             Paul Evans
58              
59             =cut
60              
61             0x55AA;