App-Module-Template
view release on metacpan or search on metacpan
lib/App/Module/Template.pm view on Meta::CPAN
package App::Module::Template;
use 5.016;
use strict;
use warnings;
our $VERSION = '0.11';
use base qw(Exporter);
use App::Module::Template::Initialize;
use Carp;
use Config::General;
use File::Copy;
use File::HomeDir;
use File::Path qw/make_path/;
use File::Spec;
use Getopt::Std;
use POSIX qw(strftime);
use Template;
use Try::Tiny;
our (@EXPORT_OK, %EXPORT_TAGS);
@EXPORT_OK = qw(
run
_get_config
_get_config_path
_get_module_dirs
_get_module_fqfn
_get_template_path
_module_path_exists
_process_dirs
_process_file
_process_template
_validate_module_name
);
%EXPORT_TAGS = (
ALL => [ @EXPORT_OK ],
);
#-------------------------------------------------------------------------------
sub run {
my $class = shift;
my %opt;
# -c config file
# -m module name
# -t template dir, location of template files
getopts('c:m:t:', \%opt);
unless ( ( exists $opt{m} ) and ( defined $opt{m} ) ) {
croak "-m <Module::Name> is required. exiting...\n";
}
my $module = $opt{m};
my $dist = $module; $dist =~ s/::/-/gmsx;
my $file = $module; $file =~ s/.*:://msx; $file .= '.pm';
my $dist_dir = File::Spec->catdir( File::Spec->curdir, $dist );
my $tmpl_vars;
try {
_validate_module_name($module);
} catch {
croak "$_ module-template. exiting...";
};
if ( _module_path_exists($dist_dir) ) {
croak "Destination directory $dist_dir exists. exiting...";
}
my $template_dir = _get_template_path($opt{t});
my $config_file = _get_config_path($opt{c}, $template_dir);
my $cfg = _get_config($config_file);
# Setting this lets TT2 handle creating the destination files/directories
$cfg->{template_toolkit}{OUTPUT_PATH} = $dist_dir;
my $tt2 = Template->new( $cfg->{template_toolkit} );
lib/App/Module/Template.pm view on Meta::CPAN
=pod
=head1 NAME
App::Module::Template - Perl module scaffolding with Template Toolkit
=head1 VERSION
This documentation refers to App::Module::Template version 0.11.
=head1 SYNOPSIS
use App::Module::Template;
App::Module::Template->run(@ARGS);
=head1 DESCRIPTION
App::Module::Template contains the subroutines to support 'module-template'. See module-template for usage.
=head1 SUBROUTINES/METHODS
=over
=item C<run>
This function is called by module-template to execute logic of the program.
=back
=head1 DIAGNOSTICS
None.
=head1 CONFIGURATION AND ENVIRONMENT
App::Module::Template is configured by ~/.module-template/config. See module-template for more information.
=head1 DEPENDENCIES
=over
=item * Carp
=item * Config::General
=item * File::Copy
=item * File::HomeDir
=item * File::Path
=item * File::Spec
=item * Getopt::Std
=item * POSIX
=item * Template
=item * Try::Tiny
=back
=head1 INCOMPATIBILITIES
None reported.
=head1 BUGS AND LIMITATIONS
No bugs have been reported.
Please report any issues or feature requests to L<https://github.com/tscornpropst/App-Module-Template/issues>. Patches are welcome.
=head1 AUTHOR
Trevor S. Cornpropst <tscornpropst@gmail.com>
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2014 Trevor S. Cornpropst <tscornpropst@gmail.com>. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:
L<http://www.perlfoundation.org/artistic_license_2_0>
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=cut
( run in 0.869 second using v1.01-cache-2.11-cpan-39bf76dae61 )