Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Turning a script into a module

by barbie (Deacon)
on Jul 17, 2003 at 08:43 UTC ( [id://275150]=note: print w/replies, xml ) Need Help??


in reply to Turning a script into a module

Rather than thinking about warn and die when something goes wrong, think about return codes.

If something goes horribly wrong, I usually return undef, then the caller can check whether anything was returned and handle it as it wishes. In some cases I also setup an internal error code and/or error message (ERRNO, ERRMESS), which can be accessed like Package::ERRNO. This then puts the reliance on the caller to handle the errors as they see fit.

Regards having a PrintHandler, passing that as you have seems fine, but if this is just for warnings and errors, I would personally use the return codes. Then again if this is for own use then it probably isn't an issue, if it was for CPAN you might want to consider that others might not want to print anything at all.

--
Barbie | Birmingham Perl Mongers | http://birmingham.pm.org/

Replies are listed 'Best First'.
Re: Re: Turning a script into a module
by eyepopslikeamosquito (Archbishop) on Jul 17, 2003 at 09:16 UTC

    If you want to see nothing at all, you can use:

    PrintHandler => sub {}

    Many of the methods are very long-running, so most users want feedback about their status (and that the machine has not hung). A PrintHandler callback function is the best I have thought of so far. I suppose a GUI front-end could display the status message in a window.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found