Changeset 10894 for lang/perl/arguments

Show
Ignore:
Timestamp:
05/01/08 22:20:21 (7 months ago)
Author:
takesako
Message:

lang/perl/arguments: 0.02 - supported arguments->length

Location:
lang/perl/arguments/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/arguments/trunk/Changes

    r10886 r10894  
    11Revision history for Perl extension arguments. 
    22 
    3 0.01  Thu May  1 16:34:55 2008 
     30.02  Thu May  1 22:04:15 JST 2008 
     4        - supported: arguments->callee 
     5        - supported: arguments->length 
     6 
     70.01  Thu May  1 16:34:55 JST 2008 
    48        - original version; created  
    59 
  • lang/perl/arguments/trunk/README

    r10886 r10894  
    1 arguments version 0.01 
     1arguments version 0.02 
    22====================== 
    33 
  • lang/perl/arguments/trunk/lib/arguments.pm

    r10886 r10894  
    44use warnings; 
    55 
    6 our $VERSION = '0.01'; 
     6our $VERSION = '0.02'; 
     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} 
    723 
    824require XSLoader; 
     
    1026 
    1127sub callee { 
    12     my $level = shift; 
    13     $level = 0 if (!defined $level); 
    14     my $cx = _upcontext($level + 1); 
     28    my $cx = _upcontext(1); 
    1529    return unless $cx; 
    1630    return _context_cv($cx); 
     
    2842  use arguments; 
    2943 
     44  print sub { 
     45    my $x = shift; 
     46    return 1 if ($x <= 1); 
     47    return $x * arguments->callee->($x - 1); 
     48  }->(5); # 120 
     49 
    3050  sub { 
    3151    my $c = shift; 
    3252    print "$c\n"; 
    33     arguments::callee->($c) if ($c--); 
     53    arguments->callee->($c) if ($c--); 
    3454  }->(10); 
    3555 
     
    4060see also. 
    4161http://d.hatena.ne.jp/amachang/20080501/1209623634 
     62http://d.hatena.ne.jp/amachang/20080501/1209640306 
    4263 
    4364=head1 SEE ALSO 
  • lang/perl/arguments/trunk/t/arguments.t

    r10886 r10894  
    1 use Test::More tests => 5; 
     1use Test::More tests => 9; 
    22BEGIN { use_ok('arguments') }; 
    33 
     
    1414}->(3); 
    1515 
     16my $n = sub { 
     17  my $x = shift; 
     18  return 1 if ($x <= 1); 
     19  return $x * arguments::callee->($x - 1); 
     20}->(5); 
     21ok($n == 120); 
     22 
     23 
     24sub func { 
     25  ok(arguments->callee eq \&func); 
     26  ok(arguments->length == 3); 
     27  my @a = arguments(); 
     28  ok(scalar @a == 3); 
     29} 
     30func(1,2,3); 
     31 
     32