This file is indexed.

/usr/share/perl5/CPS/Governor.pm is in libcps-perl 0.17-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#  You may distribute under the terms of either the GNU General Public License
#  or the Artistic License (the same terms as Perl itself)
#
#  (C) Paul Evans, 2009 -- leonerd@leonerd.org.uk

package CPS::Governor;

use strict;
use warnings;

use Carp;

our $VERSION = '0.17';

=head1 NAME

C<CPS::Governor> - control the iteration of the C<CPS> functions

=head1 DESCRIPTION

Objects based on this abstract class are used by the C<gk*> variants of the
L<CPS> functions, to control their behavior. These objects are expected to
provide a method, C<again>, which the functions will use to re-invoke
iterations of loops, and so on. By providing a different implementation of
this method, governor objects can provide such behaviours as rate-limiting,
asynchronisation or parallelism, and integration with event-based IO
frameworks.

=cut

=head1 CONSTRUCTOR

=cut

=head2 $gov = CPS::Governor->new

Must be called on a subclass which implements the C<again> method. Returns a
new instance of a governor object in that class.

=cut

sub new
{
   my $class = shift;
   $class->can( "again" ) or croak "Expected to be class that can ->again";
   return bless {}, $class;
}

# We're using this internally in gkpar() but not documenting it currently.
# Details are still experimental.
sub enter
{
   my $self = shift;
   $self->again( @_ );
}

=head1 SUBCLASS METHODS

Because this is an abstract class, instances of it can only be constructed on
a subclass which implements the following methods:

=cut

=head2 $gov->again( $code, @args )

Execute the function given in the C<CODE> reference C<$code>, passing in the
arguments C<@args>. If this is going to be executed immediately, it should
be invoked using a tail-call directly by the C<again> method, so that the
stack does not grow arbitrarily. This can be achieved by, for example:

 @_ = @args;
 goto &$code;

Alternatively, the L<Sub::Call::Tail> may be used to apply syntactic sugar,
allowing you to write instead:

 use Sub::Call::Tail;
 ...
 tail $code->( @args );

=cut

=head1 EXAMPLES

=head2 A Governor With A Time Delay

Consider the following subclass, which implements a C<CPS::Governor> subclass
that calls C<sleep()> between every invocation.

 package Governor::Sleep

 use base qw( CPS::Governor );

 sub new
 {
    my $class = shift;
    my ( $delay ) = @_;

    my $self = $class->SUPER::new;
    $self->{delay} = $delay;

    return $self;
 }

 sub again
 {
    my $self = shift;
    my $code = shift;

    sleep $self->{delay};

    # @args are still in @_
    goto &$code;
 }

=cut

=head1 SEE ALSO

=over 4

=item *

L<Sub::Call::Tail> - Tail calls for subroutines and methods

=back

=head1 AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

=cut

0x55AA;