use strict; package Foo; sub new { my $self = {}; bless $self, 'Foo'; } sub bar { my $self = shift(); if (@_ == 0) { return "Call \$foo->bar()"; } else { return "Call \$foo->bar( '" . join("', '", @_) . "')"; } } package main; my $foo = new Foo; use Interpolation 'foo:$@->$' => sub { my $cmd = shift(); no strict 'refs'; $foo->$cmd(@_); }; # this creates a tied PACKAGE variable %main::foo !!! print "x $foo{bar}\n"; print "x $foo{bar}{1}\n"; print "x $foo{bar}{1,2}\n"; # if you want the arrow just create a reference to the %main::foo my $Foo = \%foo; print "x $Foo->{bar}\n"; print "x $Foo->{bar}{1}\n"; print "x $Foo->{bar}{1,2}\n"; #### ... package main; use Interpolation; my $foo = new Foo; my $Foo = {}; tie %$Foo, 'Interpolation::general', sub { my $cmd = shift(); no strict 'refs'; $foo->$cmd(@_); }, '$@->$'; print "x $Foo->{bar}\n"; print "x $Foo->{bar}{1}\n"; print "x $Foo->{bar}{1,2}\n"; #### ... package main; use Interpolation; my $foo = new Foo; my $CALL = {}; tie %$CALL, 'Interpolation::general', sub { my $obj = shift(); my $cmd = shift(); no strict 'refs'; $obj->$cmd(@_); }, '$$@->$'; print "x $CALL->{$foo}->{bar}\n"; print "x $CALL->{$foo}->{bar}{1}\n"; print "x $CALL->{$foo}->{bar}{1,2}\n"; #### package Foo; sub baz { my $self = shift(); foreach (@_) { print "$_ is a ".(ref $_ ? "reference" : "string")."\n"; } } ... package main; my $FooX = {}; tie %$FooX, 'Interpolation::general', sub { my $cmd = shift(); no strict 'refs'; $foo->$cmd(@_); }, '$$*->$'; print "x $FooX->{baz}{1}{2}{$foo}\n"; or my $CALLX = {}; tie %$CALLX, 'Interpolation::general', sub { my $obj = shift(); #print "Yep it's a ref\n" if ref $obj; my $cmd = shift(); no strict 'refs'; $obj->$cmd(@_); }, '$$$*->$'; print "x $CALLX->{$foo}->{baz}{$ref}{100}{$object}\n";