Dist-Maker

 view release on metacpan or  search on metacpan

lib/Dist/Maker/Template/CLI.pm  view on Meta::CPAN

package Dist::Maker::Template::CLI;
use utf8;
use Mouse;
use MouseX::StrictConstructor;

extends 'Dist::Maker::Template::Default';
with    'Dist::Maker::Template';

sub distribution {
    return <<'DIST';
: cascade Default;

:# @@ Makefile.PL

: after mpl_requires {
requires 'Getopt::Long' => '2.37';
: }

: after mpl_footer {
install_script '<: $dist.moniker :>';
: }

:# @@ lib/$dist.module_path
: after module_code -> {
use Getopt::Long ();

sub getopt_spec {
    return(
        'version',
        'help',
    );
}

sub getopt_parser {
    return Getopt::Long::Parser->new(
        config => [qw(
            no_ignore_case
            bundling
            no_auto_abbrev
        )],
    );
}

sub appname {
    my($self) = @_;
    require File::Basename;
    return File::Basename::basename($0);
}

sub new {
    my $class = shift;
    local @ARGV = @_;

    my %opts;
    my $success = $class->getopt_parser->getoptions(
        \%opts,
        $class->getopt_spec());

    if(!$success) {
        $opts{help}++;
        $opts{getopt_failed}++;
    }

    $opts{argv} = \@ARGV;

    return bless \%opts, $class;
}

sub run {
    my $self = shift;

    if($self->{help}) {
        $self->do_help();
    }
    elsif($self->{version}) {
        $self->do_version();
    }
    else {
        $self->dispatch(@ARGV);
    }

    return;
}

sub dispatch {
    my($self, @args) = @_;
    print Dump($self);
    return;
}

sub Dump {
    my($data, $name) = @_;
    require Data::Dumper;
    my $dd = Data::Dumper->new([$data], [$name || 'app']);
    $dd->Indent(1);
    $dd->Maxdepth(3);
    $dd->Quotekeys(0);
    $dd->Sortkeys(1);
    return $dd->Dump();
}

sub do_help {
    my($self) = @_;
    if($self->{getopt_failed}) {
        die $self->help_message();
    }
    else {
        print $self->help_message();
    }
}

sub do_version {



( run in 1.928 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )