{ package Object::MethodChain; use overload q[""], "__Set_MethodChain__"; AUTOLOAD { my $self = shift; my $class = ref($self) || $self; my @new = ref($self) ? @$self : (); our $AUTOLOAD =~ /.*::(.*)/s or die "error: invalid method name"; push @new, {"method", $1, "args", \@_}; bless \@new, $class; } our $chain; sub __Set_MethodChain__ { $chain = $_[0]; "__Call_MethodChain__"; } sub UNIVERSAL::__Call_MethodChain__ { my $r = $_[0]; for my $pair (@$chain) { my($method, $args) = @$pair{"method", "args"}; $r = $r->$method(@$args); } $r; } DESTROY { } }