in reply to Re^2: multiple method calls against the same object, revisited
in thread multiple method calls against the same object, revisited
Here is a similar solution inspired by your code.
package Chain; sub new { my $proto = shift; my $self = {obj => shift}; bless $self, $proto; return $self; } sub AUTOLOAD { my $self = shift; my ( $method ) = ( our $AUTOLOAD =~ /.*::(.*)/ ); $self->{obj}->$method( @_ ); $self; } 1;
Now we can just do Chain->new($obj) and call methods on that object expecting the object itself as a return. I'm sure this could be cleaned up to handle errors etc.
use strict; use warnings; use lib "."; use Chain; use Test; my $t = new Test; $t->hello; $t->cool(1,2); Chain->new($t) ->test ->hell(1,2,3) ->say("hello");
___________
Eric Hodges
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: multiple method calls against the same object, revisited
by Aristotle (Chancellor) on Dec 28, 2004 at 22:10 UTC | |
by eric256 (Parson) on Dec 28, 2004 at 23:14 UTC | |
Re^4: multiple method calls against the same object, revisited
by dragonchild (Archbishop) on Dec 28, 2004 at 18:35 UTC | |
by eric256 (Parson) on Dec 28, 2004 at 19:30 UTC |
In Section
Cool Uses for Perl