Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: chaining method calls (smart error object)

by submersible_toaster (Chaplain)
on Jun 12, 2003 at 06:56 UTC ( #265290=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Re: chaining method calls (smart error object)
Select or Download Code
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://265290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-10-20 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (74 votes), past polls