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

Re: Testing legacy CGI scripts using the "main() unless caller()" technique

by choroba (Cardinal)
on Jul 20, 2022 at 21:48 UTC ( [id://11145613]=note: print w/replies, xml ) Need Help??


in reply to Testing legacy CGI scripts using the "main() unless caller()" technique

You never know that the expression in unless caller() is the last evaluated one. There can be many more expressions scattered among the sub definitions, setting lexical variables or whatever. Putting a true value at the very end of the file means it will always behave correctly, regardless of the changes in the unless versus if ! line, or anywhere else.

BTW, You might notice my pm files usually end with the following line:

__PACKAGE__

It's a true value (I don't use 0.pm), but more importantly, there's no semicolon after it. If you try adding another sub or anything else below it, you'll get a syntax error. (I do the same thing with return). Your taste might be different.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found