#!/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 - [A line to describe the script] =head1 VERSION See version at beginning of script, variable $VERSION. =head1 EXAMPLES shell$ =for the author: Some brief example to show the most common usage for the script. This will probably be the most read section, so include meaningful examples. =head1 USAGE [--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. 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 =head1 LICENCE AND COPYRIGHT Copyright (c) 2006, Flavio Poletti C. All rights reserved. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L and L. =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 WHEN 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. THE 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 #### #!/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/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. 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 file. This is not allowed, script-starter won't let you shoot at your feet so easily. Note that there is still space for a race condition between the existence test and the actual file open for writing, be sure to aim well. =item C<< open() for original '/path/to/template': >> There was a problem opening the template file. =item C<< open() on '/path/to/target-script': >> 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 rights reserved. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L and L. Questo script è software libero: potete ridistribuirlo e/o modificarlo negli stessi termini di Perl stesso. Vedete anche L e L. =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 WHEN 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. THE 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 espressa 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 redistribuire 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, derivanti dall'utilizzo o dall'incapacità di utilizzo di questo software. Ciò include, a puro titolo di esempio e senza limitarsi ad essi, la perdita 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 altra 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 espressamente questa negazione di garanzia e la piena responsabilità per qualsiasi tipo di danno, di qualsiasi natura, possa derivarne. =cut