http://www.perlmonks.org?node_id=265290


in reply to Re: chaining method calls (smart error object)
in thread chaining method calls

I like your idea, enough even to have a bash at it myself, moreso for educational purposes than anything. The first thing that struck me thought was "How can AUTOLOAD determine boolean context?". I know that wantarray will define whether the calling context is list, scalar or void. However I am stumped when it comes to determining boolean context.

If I have you right.., and Some::Package returns error objects on failure.

my $obj = Some::Package->new( %params ); $obj->connect()->synchronise()->disconnect();
Presuming the new method fails, returning an error object (populated with some meaningful message), then the call to connect will be caught by the error object's AUTOLOAD. At this point we determine context, and depending on that confess.

Is there nothing already out-there to do this? I'm off to CPAN first. ++tye


I can't believe it's not psellchecked

Replies are listed 'Best First'.
Re^3: chaining method calls (smart error object)
by adrianh (Chancellor) on Jun 12, 2003 at 10:09 UTC
    The first thing that struck me thought was "How can AUTOLOAD determine boolean context?".

    AUTOLOAD doesn't have to. You overload bool and use it to set some internal flag in the object to say it's been evaluated in a boolean context. Then in DESTROY you throw an exception if the flag has not been set.