App-Basis

 view release on metacpan or  search on metacpan

bin/appbasis  view on Meta::CPAN

#!/usr/bin/env perl
# PODNAME: appbasis - simple script to create a boilerplate app
# ABSTRACT: Create a boilerplate app for App::Basis


use strict;
use warnings;
use App::Basis ;
use Path::Tiny;

# -----------------------------------------------------------------------------
# main

my %opt = init_app(
    help_text    => "Create a new App::Basis app",
    help_cmdline => "filepath_of_file_to_create",
    options      => {
        'overwrite|o' => 'allow overwrite of existing file',
    } 
);

my $appname = $ARGV[0];

show_usage( "You need to provide the filepath") if ( !$appname ) ;
show_usage( "$appname already exists, not overwriting") if ( -f $appname && !$opt{ overwrite} ) ;

my $path = path($appname)->dirname;
path($path)->mkpath if ($path);

# read the data section after __END__
my $boilerplate = join( "", <DATA> );
my $shortname = path( $appname)->basename ;
$boilerplate =~ s/%%APPNAME%%/$shortname/gsm;
# remove the leading '|' that is used to keep the boilerplate doc header away 
# from the pod for this app
$boilerplate =~ s/^\|//gsm ;

path($appname)->spew($boilerplate);
if ( -f $appname ) {

    # being lazy, not reading in the current value and updating and writing back
    system("chmod a+x '$appname'");
    print "app $appname created.\n";
}
else {
    print "failed to create $appname\n";
    exit 1;
}

exit 0;

# this is the boilerplate

=pod

=encoding UTF-8

=head1 NAME

appbasis - simple script to create a boilerplate app - Create a boilerplate app for App::Basis

=head1 VERSION

version 1.2

=head1 SYNOPSIS

    > appbasis file/to/create

=head1 DESCRIPTION

Create the boilerplate for an L<App::Basis> application.

This simple script creates all you need to get started, adds command line 
handling and config file

=head1 AUTHOR

Kevin Mulholland <moodfarm@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Kevin Mulholland.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

__END__
|#!/usr/bin/env perl
|# PODNAME: %%APPNAME%% - simple script to ...
|# ABSTRACT: Create a boilerplate app for App::Basis
|
|=head1 NAME
|
|%%APPNAME%%
|
|=head1 SYNOPSIS
|
|    > %%APPNAME%% ..options..
|



( run in 0.638 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )