Changeset 10894 for lang/perl/arguments
- Timestamp:
- 05/01/08 22:20:21 (7 months ago)
- Location:
- lang/perl/arguments/trunk
- Files:
-
- 4 modified
-
Changes (modified) (1 diff)
-
README (modified) (1 diff)
-
lib/arguments.pm (modified) (4 diffs)
-
t/arguments.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/arguments/trunk/Changes
r10886 r10894 1 1 Revision history for Perl extension arguments. 2 2 3 0.01 Thu May 1 16:34:55 2008 3 0.02 Thu May 1 22:04:15 JST 2008 4 - supported: arguments->callee 5 - supported: arguments->length 6 7 0.01 Thu May 1 16:34:55 JST 2008 4 8 - original version; created 5 9 -
lang/perl/arguments/trunk/README
r10886 r10894 1 arguments version 0.0 11 arguments version 0.02 2 2 ====================== 3 3 -
lang/perl/arguments/trunk/lib/arguments.pm
r10886 r10894 4 4 use warnings; 5 5 6 our $VERSION = '0.01'; 6 our $VERSION = '0.02'; 7 8 use Exporter; 9 our @ISA = qw(Exporter); 10 our @EXPORT = qw(arguments); 11 12 sub arguments { 13 { package DB; () = caller(1); } 14 return wantarray 15 ? @DB::args 16 : bless \@DB::args, 'arguments'; 17 } 18 19 sub length { 20 { package DB; () = caller(1); } 21 return scalar @DB::args; 22 } 7 23 8 24 require XSLoader; … … 10 26 11 27 sub callee { 12 my $level = shift; 13 $level = 0 if (!defined $level); 14 my $cx = _upcontext($level + 1); 28 my $cx = _upcontext(1); 15 29 return unless $cx; 16 30 return _context_cv($cx); … … 28 42 use arguments; 29 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 30 50 sub { 31 51 my $c = shift; 32 52 print "$c\n"; 33 arguments ::callee->($c) if ($c--);53 arguments->callee->($c) if ($c--); 34 54 }->(10); 35 55 … … 40 60 see also. 41 61 http://d.hatena.ne.jp/amachang/20080501/1209623634 62 http://d.hatena.ne.jp/amachang/20080501/1209640306 42 63 43 64 =head1 SEE ALSO -
lang/perl/arguments/trunk/t/arguments.t
r10886 r10894 1 use Test::More tests => 5;1 use Test::More tests => 9; 2 2 BEGIN { use_ok('arguments') }; 3 3 … … 14 14 }->(3); 15 15 16 my $n = sub { 17 my $x = shift; 18 return 1 if ($x <= 1); 19 return $x * arguments::callee->($x - 1); 20 }->(5); 21 ok($n == 120); 22 23 24 sub func { 25 ok(arguments->callee eq \&func); 26 ok(arguments->length == 3); 27 my @a = arguments(); 28 ok(scalar @a == 3); 29 } 30 func(1,2,3); 31 32
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)