Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dvwright/Perl-RunEND
Browse files Browse the repository at this point in the history
  • Loading branch information
dvwright committed Dec 5, 2012
2 parents 044a330 + d93e4d6 commit a7a3dec
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions 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__':
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a7a3dec

Please sign in to comment.