root/lang/perl/arguments/trunk/lib/arguments.pm @ 14596

Revision 14596, 1.1 kB (checked in by takesako, 6 years ago)

oops

Line 
1package arguments;
2
3use strict;
4use warnings;
5
6our $VERSION = '0.03';
7
8use Exporter;
9our @ISA = qw(Exporter);
10our @EXPORT = qw(arguments);
11
12sub arguments {
13  { package DB; () = caller(1); }
14  return wantarray
15    ? @DB::args
16    : bless \@DB::args, 'arguments';
17}
18
19sub length {
20  { package DB; () = caller(1); }
21  return scalar @DB::args;
22}
23
24require XSLoader;
25XSLoader::load('arguments', $VERSION);
26
27sub callee {
28    my $cx = upcontext(1);
29    return sub {} unless $cx;
30    return $cx;
31}
32
331;
34__END__
35
36=head1 NAME
37
38arguments.xs - Perl extension for arguments::callee
39
40=head1 SYNOPSIS
41
42  use arguments;
43
44  print sub {
45    my $x = shift;
46    return 1 if ($x <= 1);
47    return $x * arguments->callee->($x - 1);
48  }->(5); # 120
49
50  sub {
51    my $c = shift;
52    print "$c\n";
53    arguments->callee->($c) if ($c--);
54  }->(10);
55
56=head1 DESCRIPTION
57
58inspired by arguments.callee from ECMAScript.
59
60see also.
61http://d.hatena.ne.jp/amachang/20080501/1209623634
62http://d.hatena.ne.jp/amachang/20080501/1209640306
63
64=head1 SEE ALSO
65
66Devel::Caller, PadWalker
67
68=head1 LICENSE
69
70This library is free software; you can redistribute it and/or modify
71it under the same terms as Perl itself.
72
73=cut
Note: See TracBrowser for help on using the browser.