From d93e4d6df62f37c4d31d78333dd191e4d6d870e1 Mon Sep 17 00:00:00 2001 From: dvwright Date: Sat, 1 Dec 2012 19:45:04 -0800 Subject: [PATCH] Update README --- README | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/README b/README index 3785221..f51f81d 100644 --- a/README +++ b/README @@ -1,5 +1,10 @@ Perl-RunEND - Execute perl code after __END__ literal +USAGE: + + perl-run-end /opt/Module/Whatever/YourModule.pm + + A common best-practice under Python is to include a self-test at the end every module - especially if the module is largely standalone. In Python this is done via: if __name__ == '__main__': @@ -35,6 +40,76 @@ probably introducing a new literal would be best like __RUN__ which would act just like __END__ . The code contained within would only be exectuted if perl was called with the command line switch. +=head1 SYNOPSIS + +If module is called as 'self' run the code beneath __END__. + + + perl-run-end /opt/Module/Whatever/YourModule.pm + # displays + FOOfunction1 called + + Where the contents of ModuleWhatever/YourModule.pm + + package YourModule; + use strict; + sub new { + my $class = shift; + my $self = bless {}, $class; + $self->{foo} = 'FOO'; + return $self; + } + sub function1 { + return 'function1 called'; + } + 1; # End of Perl::RunEND + + __END__ + use strict; + use warnings; + use YourModule; + my $ym = YourModule->new(); + warn $ym->{foo}; + warn $ym->function1; + + # you may have to add the module path to your @INC + perl-run-end -i /opt/Module/Whatever/Mod /opt/Module/Whatever/Mod/YourModule.pm + +=head1 DESCRIPTION + +Some people like to create their POD below the __END__ literal in the modules + +This module could be useful for proving your synopsis and POD examples are working code. + +Consider the following POD: + + =head1 SYNOPSIS + + use My::MyModulePod; + my $mm = My::MyModulePod->new(); + print $mm->function1,"\n"; + + =cut + + # perdoc does not parse this code but perl-run-end does execute it + use My::MyModulePod; + my $mm = My::MyModulePod->new(); + print "test synopsis\n"; + print $mm->function1,"\n"; + + =head2 function1 + + provides useful funtion type access + + $mm->function1; + + =cut + + print "test method definition\n"; + print $mm->function1,"\n"; + + + INSTALLATION