Skip to content
Browse files

Update README

  • Loading branch information...
1 parent 7ca8f35 commit d93e4d6df62f37c4d31d78333dd191e4d6d870e1 @dvwright committed Dec 1, 2012
Showing with 75 additions and 0 deletions.
  1. +75 −0 README
View
75 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

0 comments on commit d93e4d6

Please sign in to comment.
Something went wrong with that request. Please try again.