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

modulino and $VERSION

by neilwatson (Priest)
on Jul 10, 2014 at 17:35 UTC ( [id://1093093]=perlquestion: print w/replies, xml ) Need Help??

neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I'm attempting to learn brian_d_foy's modulino. In this early prototype I'm getting an uninitialized error about $VERSION. What is the cause?

#!/usr/bin/perl use strict; use warnings; use feature qw/say/; use vars qw/$VERSION/; $VERSION = 0.01; UNITCHECK { sub _running_under_docreader { !! $ENV{PERLDOC} } sub _running_under_tester { !! $ENV{HARNESS_ACTIVE} } sub _running_as_app { defined scalar caller } my $method = do { if( _running_under_docreader() ) { 'doc' } # reading docs elsif( _running_under_tester() ) { 'test' } # testing elsif( _running_as_app() ) { 'run' } # running the appli +cation else { undef } # everything else }; __PACKAGE__->$method(@ARGV) if defined $method; } sub run { say $VERSION; } $ ./foo.pl Use of uninitialized value $VERSION in say at ./foo.pl line 36.

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: modulino and $VERSION
by AppleFritter (Vicar) on Jul 10, 2014 at 17:53 UTC

    UNITCHECK blocks are run right after a unit has been compiled, before runtime (see perlmod), so $VERSION has not been initialized by the time you call run(). Try setting it like this:

    BEGIN { $VERSION = 0.01; }
Re: modulino and $VERSION (all code in module , script as module )
by Anonymous Monk on Jul 11, 2014 at 03:30 UTC

    Greetings, I'm attempting to learn brian_d_foy's modulino. In this early prototype I'm getting an uninitialized error about $VERSION. What is the cause?

    You've pasted a module into a script -- that is anti-modulino friend

    I didn't realize until now that his modulino demo has that UNITCHECK stuff -- it doesn't belong in 99.9999% of code

    The most useful part of the modulino idea is having all code in modules, and having your program , your foo.pl call one function, say  use MyModulino; MyModulino::MainCLI();

    This is whats most important part of modulino idea, that code is in the module, its modular, its testable, its extensible

    The anti-modulino way is put all the code in foo.pl and App::MyModulino is just empty module with $VERSION number

    I guess all this time he's been to make modulino mean something beyond "script as module" -- and all this time I've been using modulino as script-as-module

    Whoa

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-24 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found