Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2016-10-23 19:05 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.