neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
Greetings again,
Regarding Modulino::Demo, specifically the following sections. How does the doc sub work? Is it supposed to run when the module is called using perldoc? I did try it, but I didn't see the s/__PACKAGE__/$package/; happen. Have I got it all wrong?
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 else { undef } # everything else }; sub doc { say "Running as docs"; my $data = do { local( @ARGV, $/ ) = __FILE__; <>; }; my $package = __PACKAGE__; $data =~ s/__PACKAGE__/$package/; # AND << say $data; }
Neil Watson
watson-wilson.ca
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: modulino and perldoc (perldoc -MModulino::Demo2 Modulino::Demo2 background)
by Anonymous Monk on Jul 11, 2014 at 06:46 UTC |