Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Handling non-fatal method error strings without exceptions or globals?

by dragonchild (Archbishop)
on Jan 19, 2005 at 16:22 UTC ( #423425=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Handling non-fatal method error strings without exceptions or globals?
in thread Handling non-fatal method error strings without exceptions or globals?

# This code has been run through a basic smoke-test. package My::Error::String; use overload '""' => \&stringify, '0+' => \&boolify, fallback => 1; sub new { my $class = shift; my $error = shift; bless \$error, $class; } sub stringify { my $self = shift; return $$self; } sub boolify { return; }

Then, when you want to use it, you'd do something like:

use My::Error::String; sub func_with_error { if ($have_error) { return My::Error::String->new( "Have an error somewhere ..." ) +; } }

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.


Comment on Re^3: Handling non-fatal method error strings without exceptions or globals?
Select or Download Code
Re^4: Handling non-fatal method error strings without exceptions or globals?
by Tanktalus (Canon) on Jan 19, 2005 at 16:34 UTC

    Note that if you don't have an error, this code is assuming you will not return an object. (Just want to make clear the reason why boolify always returns false.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-04-20 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (487 votes), past polls