use overload を使ってみた
package Acme::JS::Arguments; use strict; use warnings; use Devel::Caller qw(caller_args); use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(arguments callee); sub arguments { bless [ caller_args(1) ], 'Acme::JS::Arguments::Callee' } sub callee { my $self = '__callee__'; bless \$self, 'Acme::JS::Arguments::Callee' } package Acme::JS::Arguments::Callee; use Devel::Caller qw(caller_cv); use overload '.' => sub { my ($self, $obj) = @_; return caller_cv(1) if (ref $obj eq 'Acme::JS::Arguments::Callee' and $$obj eq '__callee__') }; sub callee { caller_cv(1) } 1;
これを使えば、以下のような感じで arguments.callee とも書けます
use strict; use warnings; use Acme::JS::Arguments; use Data::Dumper; sub hoge { print Dumper(arguments); print Dumper(arguments.callee); print Dumper(arguments.callee == \&hoge); print Dumper(arguments->callee); print Dumper(arguments->callee == \&hoge); } hoge(1, 2, 3)