callee - support recursive anonymous functions


callee documentation Contained in the callee distribution.

Index


Code Index:

NAME

Top

callee - support recursive anonymous functions

VERSION

Top

version 1.100820

SYNOPSIS

Top

    use callee;

    my $f = sub {
        my $x = shift;
        return 1 if $x <= 1;
        $x * callee->($x-1);
    }->(5);

    # $f is 120

DESCRIPTION

Top

This module exports one function, callee(), which allows anonymous functions to refer to themselves. This is necessary for recursive anonymous functions.

A recursive function must be able to refer to itself. Typically, a function refers to itself by its name. However, an anonymous function does not have a name, and if there is no accessible variable referring to it, i.e. the function is not assigned to any variable, the function cannot refer to itself. This is where callee comes in.

This module is just very thin syntactic sugar for Devel::Caller.

FUNCTIONS

Top

callee

Returns a coderef to the function within which it is called.

SEE ALSO

Top

Takesako-san wrote arguments.pm - see http://svn.coderepos.org/share/lang/perl/arguments/trunk/ - which does practically the same thing; see also his blog entry (in Japanese): http://d.hatena.ne.jp/TAKESAKO/20080501/1209637452.

I released this module because arguments.pm is not on CPAN, and because Devel::Caller already existed on CPAN, but not with the syntax I wanted.

INSTALLATION

Top

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=callee.

AVAILABILITY

Top

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/callee/.

The development version lives at http://github.com/hanekomu/callee/. Instead of sending patches, please fork this project using the standard git and github infrastructure.

AUTHOR

Top

  Marcel Gruenauer <marcel@cpan.org>

COPYRIGHT AND LICENSE

Top


callee documentation Contained in the callee distribution.

use 5.008;
use strict;
use warnings;

package callee;
our $VERSION = '1.100820';
# ABSTRACT: support recursive anonymous functions
use Devel::Caller qw(caller_cv);
use Exporter qw(import);
our @EXPORT  = qw(callee);
sub callee { caller_cv(1) }
1;


__END__