Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Modules as executable scripts?

by friedo (Prior)
on Jun 15, 2007 at 02:14 UTC ( #621383=note: print w/replies, xml ) Need Help??


in reply to Modules as executable scripts?

I typically do this:

package Runnable; sub do_something { ... } __PACKAGE__->do_something unless caller; 1;

Then I can execute the module itself as if it were a script. This is great for command-line tools that need to use inheritance or other OO-ish stuff. For a current project, I have my entire Test::Class-based test-suite implemented this way, so the test classes can be run as if they were .t files, but they inherit parent class tests.

Update: Here is a node that discusses this technique in more detail: How a script becomes a module

Replies are listed 'Best First'.
Re^2: Modules as executable scripts?
by bsb (Priest) on Jun 15, 2007 at 03:25 UTC
    For PAR compatibility I use:
    __PACKAGE__->do_something(@ARGV) if !caller() || caller() eq 'PAR';

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://621383]
help
Chatterbox?
[LanX]: ... the rest is loaded from a node
[holli]: the best course of action would be to transfer the data to something well tested. even if it isnt perl based
[moritz]: but even if I had all the time in the world, I wouldn't spend much on perlmonks
[LanX]: holli: LOL
[LanX]: moritz: why ? family?
[LanX]: or other language?
[moritz]: LanX because of usability issues, and the lack of evolvement
[holli]: lol to the robust charme or to the data transfer?
[holli]: it works fine with Lynx though :)
[LanX]: it's easier to patch then to migrate to a PHP board, there are many semantics like linking , authorisation, templates ,...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-11-20 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (292 votes). Check out past polls.

    Notices?