Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: testing in perl: main and caller

by bmann (Priest)
on Sep 05, 2005 at 02:14 UTC ( #489107=note: print w/replies, xml ) Need Help??

in reply to testing in perl: main and caller

I'm not sure if this is what chromatic suggested, but either one of these should do what you're looking for:
unless ( defined caller ) { #code here }
sub do_me { #code to run here } do_me unless defined caller;
sub do_me or the block after unless won't be executed when used or required, but will be executed from the command line.

From perldoc caller:

Returns the context of the current subroutine call. In scalar context, returns the caller's package name if there is a caller, that is, if we're in a subroutine or eval or require, and the undefined value otherwise.

Replies are listed 'Best First'.
Re^2: testing in perl: main and caller
by chromatic (Archbishop) on Sep 05, 2005 at 02:37 UTC

    That's basically what the book suggests. Thanks!

      what does the test code look like, then?
      isn't correct, clearly.


        The book has:

        ok( require( '' ), 'loaded file successfully' ) or exit;

        I think require_ok() would also work, though I'm not in a position to try it right now, nor do I remember if I wrote it as above for a specific reason.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://489107]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-08-23 18:08 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (355 votes). Check out past polls.