Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is the template (living in Linux, I put it into $HOME/.module-starter/script.tpl):
#!/usr/bin/perl use strict; use warnings; use Carp; use Pod::Usage qw( pod2usage ); use Getopt::Long qw( :config gnu_getopt ); use version; my $VERSION = qv('0.0.1'); my %config; GetOptions(\%config, 'usage', 'help', 'man', 'version') or pod2usage(-verbose => 99, -sections => 'USAGE');; pod2usage("$0 v$VERSION") if $config{version}; pod2usage(-verbose => 99, -sections => 'USAGE') if $config{usage}; pod2usage(-verbose => 99, -sections => 'EXAMPLES|USAGE|OPTIONS') if $config{help}; pod2usage(-verbose => 2) if $config{man}; # Other recommended modules (uncomment to use): # use IO::Prompt; # use Readonly; # use Data::Dumper; # use Log::Log4perl qw( :easy ); # Script implementation here __END__ =head1 NAME <SCRIPT-NAME> - [A line to describe the script] =head1 VERSION See version at beginning of script, variable $VERSION. =head1 EXAMPLES shell$ <SCRIPT-NAME> =for the author: Some brief example to show the most common usage for the script. Th +is will probably be the most read section, so include meaningful examples. =head1 USAGE <SCRIPT-NAME> [--usage] [--help] [--man] [--version] =for the author: Include a complete usage block of text, like any other good command =head1 DESCRIPTION =for the author: A complete description of the script and its characteristics, with +a possible structure into deeper sections (via =head2, =head3). Leave options description for the next section! =head1 OPTIONS =for the author A description of all the available options that the script accepts. The pre-defined ones are already included, of course. =over =item --usage print a concise usage line and exit. =item --help print a somewhat more verbose help, showing usage, this description of the options and some examples from the synopsis. =item --man print out the full documentation for the script. =item --version print the version of the script. =back =head1 DIAGNOSTICS =for the author Include all error messages and possible exit conditions, even those that "should never happen". =over =item C<< Error message here, perhaps with %s placeholders >> [Description of first error...] =item C<< Another error message here >> [Description of another error...] [... and so on...] =back =head1 CONFIGURATION AND ENVIRONMENT =for the author Describe any configuration file that is used by the script, and any environment variable that affects the its behaviour. Include details about the position of the files, their formats, etc. <SCRIPT-NAME> requires no configuration files or environment variables +. =head1 DEPENDENCIES =for the author A list of all modules the script is based for, together with an indication of their version and the required perl version. None. =head1 BUGS AND LIMITATIONS =for the author A list of all known problem about the script, with an indication of when (and if) they will be eventually solved. Also include a description of all feature restrictions and limitations. No bugs have been reported. Please report any bugs or feature requests to the AUTHOR =head1 AUTHOR Flavio Poletti C<flavio [at] polettix.it> =head1 LICENCE AND COPYRIGHT Copyright (c) 2006, Flavio Poletti C<flavio [at] polettix.it>. All rig +hts reserved. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L<perlartistic> and L<perlgpl>. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WH +EN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. TH +E ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut
This is the script that creates a new script based on the template above, I named it script-starter
#!/usr/bin/perl use strict; use warnings; use Carp; use Pod::Usage (); use version; my $VERSION = qv('0.0.1'); my $original = "$ENV{HOME}/.module-starter/script.tpl"; # Other recommended modules (uncomment to use): # use IO::Prompt; # use Perl6::Export; # use Perl6::Slurp; # use Perl6::Say; # use Regexp::Autoflags; # use Readonly; # Script implementation here my $script_name = shift; if (! defined $script_name ) { Pod::Usage::pod2usage(-verbose => 1); exit 0; } if ($script_name =~ /-h|--help/) { Pod::Usage::pod2usage(-verbose => 2); exit 0; } croak "file '$script_name' already exists, stopped" if -e $script_name +; open my $input_fh, '<', $original or croak "open() for original '$original': $!"; open my $output_fh, '>', $script_name or croak "open() on '$script_name': $!"; while (<$input_fh>) { s/<SCRIPT-NAME>/$script_name/g; print {$output_fh} $_; } close $input_fh; close $output_fh; __END__ =head1 NAME script-starter - create the base for a new script =head1 VERSION This document describes script-starter version 0.0.1 =head1 SYNOPSIS # Ask for help shell$ script-starter # Generate a new script from the template shell$ script-starter nome-script =head1 DESCRIPTION This script helps to create other scripts, in a way much similar to module-starter. It takes the $original script (see start of script) and copies to the destination one, setting the script name on the fly. =head1 INTERFACE The script requires only one argument, which should be a valid filename for a non-existing file. When called without options, it prints the examples in the L<SYNOPSIS> +. When called with -h/--help, it perldoc-s the script to show this help page. =head1 DIAGNOSTICS =over =item C<< file '$script_name' already exists, stopped at... >> The name of the script to be generated refers to an already existing f +ile. This is not allowed, script-starter won't let you shoot at your feet s +o easily. Note that there is still space for a race condition between th +e existence test and the actual file open for writing, be sure to aim we +ll. =item C<< open() for original '/path/to/template': <specific error> >> There was a problem opening the template file. =item C<< open() on '/path/to/target-script': <specific error> >> There was a problem opening the target file. =back =head1 CONFIGURATION AND ENVIRONMENT Given the fact that I'll never publish this script, it can be easily tweaked modifing the C<$original> variable at the beginning, which points to the template model. =head1 DEPENDENCIES A few: =over =item - version =item - Pod::Usage =back =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests through http://rt.cpan.org/ =head1 AUTHOR Flavio Poletti C<< flavio@polettix.it >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2006, Flavio Poletti C<< flavio@polettix.it >>. All righ +ts reserved. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L<perlartistic> and L<perlgpl>. Questo script è software libero: potete ridistribuirlo e/o modificarlo negli stessi termini di Perl stesso. Vedete anche L<perlartistic> e L<perlgpl>. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WH +EN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. TH +E ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =head1 NEGAZIONE DELLA GARANZIA Poiché questo software viene dato con una licenza gratuita, non c'è alcuna garanzia associata ad esso, ai fini e per quanto permesso dalle leggi applicabili. A meno di quanto possa essere specificato altrove, il proprietario e detentore del copyright fornisce questo software "così com'è" senza garanzia di alcun tipo, sia essa espress +a o implicita, includendo fra l'altro (senza però limitarsi a questo) eventuali garanzie implicite di commerciabilità e adeguatezza per uno scopo particolare. L'intero rischio riguardo alla qualità ed alle prestazioni di questo software rimane a voi. Se il software dovesse dimostrarsi difettoso, vi assumete tutte le responsabilità ed i costi per tutti i necessari servizi, riparazioni o correzioni. In nessun caso, a meno che ciò non sia richiesto dalle leggi vigenti o sia regolato da un accordo scritto, alcuno dei detentori del diritto di copyright, o qualunque altra parte che possa modificare, o redistri +buire questo software così come consentito dalla licenza di cui sopra, potr +à essere considerato responsabile nei vostri confronti per danni, ivi inclusi danni generali, speciali, incidentali o conseguenziali, deriva +nti dall'utilizzo o dall'incapacità di utilizzo di questo software. Ciò include, a puro titolo di esempio e senza limitarsi ad essi, la perdit +a di dati, l'alterazione involontaria o indesiderata di dati, le perdite sostenute da voi o da terze parti o un fallimento del software ad operare con un qualsivoglia altro software. Tale negazione di garanzia rimane in essere anche se i dententori del copyright, o qualsiasi altr +a parte, è stata avvisata della possibilità di tali danneggiamenti. Se decidete di utilizzare questo software, lo fate a vostro rischio e pericolo. Se pensate che i termini di questa negazione di garanzia non si confacciano alle vostre esigenze, o al vostro modo di considerare un software, o ancora al modo in cui avete sempre trattato software di terze parti, non usatelo. Se lo usate, accettate espressam +ente questa negazione di garanzia e la piena responsabilità per qualsiasi tipo di danno, di qualsiasi natura, possa derivarne. =cut

In reply to script-starter by polettix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-01-25 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (65 votes). Check out past polls.

    Notices?