use strict; use warnings; # Create a dummy class use Class::Struct Foo => [ attr => '$' ]; # with a dummy method sub Foo::Repeater { my $self = shift; my $times = shift || 1; return ($self->attr) x $times; # Make sure x operates in list context } # Create a dummy object my $foo = Foo->new(attr => 'foo'); # Create my interpolater. my %im; tie %im, 'InterpolateMethods'; # Example: Concatenation. print "The Foo object's attr attribute is: " . $foo->attr . "\n"; # Ugly inline print "The Foo object's attr attribute is: @{[$foo->attr]}\n"; # Use the interpolater print "The Foo object's attr attribute is: @im{ $foo->attr }\n"; # We can use the interpolater in list context as well. print "Calling Foo's Repeater(3) method yeilds: @im{ $foo->Repeater(3) }\n"; package InterpolateMethods; use Tie::Hash; sub TIEHASH { my $self = shift; my $mi = \$self; return bless $mi, $self; } sub FETCH { my $self = shift; my $key = shift; return $key; } 1; __END__ The Foo object's attr attribute is: foo The Foo object's attr attribute is: foo The Foo object's attr attribute is: foo Calling Foo's Repeater(3) method yeilds: foo foo foo