App-mgen
view release on metacpan or search on metacpan
lib/App/mgen.pm view on Meta::CPAN
moo => undef,
mo => undef,
m => undef,
immutable => undef,
autoclearn => undef,
signature => undef,
silent => undef,
dryrun => undef,
description => undef,
author => undef,
email => undef,
path => undef,
current => undef,
},
description => "",
module_name => "",
module_path => "",
author => "",
email => "",
}, $class;
return $self->_set_env->_set_options;
}
sub generate {
my $self = shift;
## code generate
# set header
my $gen = $self->_gen_default;
for my $attribute (qw/signature moose autoclearn immutable mouse moo mo m/) {
my $call = "_gen_$attribute";
$gen .= $self->$call if defined($self->{options}->{$attribute});
}
# set footer
$gen .= $self->_gen_packend . $self->_gen_pod;
## file output
my $path;
if ( !$self->{options}->{dryrun} ) {
if ( !$self->{options}->{current} ) {
$path = $self->_create_dir if !$self->{options}->{current};
} else {
my @depth = split "::", $self->{module_name};
$path = pop @depth;
$path = sprintf "%s.pm", $path;
}
my $io = IO::File->new( $path, "w" ) || die $!;
$io->print($gen);
$io->close;
}
## std output
if ( !$self->{options}->{silent} ) {
print "$gen\n";
print "OUTPUT >> $path\n" if $path;
}
return $gen;
}
sub _set_env {
my $self = shift;
$self->{module_path} = $ENV{MGEN_ROOT} ? $ENV{MGEN_ROOT} : "";
$self->{author} = $ENV{MGEN_AUTHOR} ? $ENV{MGEN_AUTHOR} : "";
$self->{email} = $ENV{MGEN_EMAIL} ? $ENV{MGEN_EMAIL} : "";
return $self;
}
sub _set_options {
my $self = shift;
# Set options
my $options = {};
my $ret = GetOptions(
'moose' => \( $options->{moose} ),
'mouse' => \( $options->{mouse} ),
'moo' => \( $options->{moo} ),
'mo' => \( $options->{mo} ),
'm' => \( $options->{m} ),
'immutable' => \( $options->{immutable} ),
'autoclearn' => \( $options->{autoclearn} ),
'signature' => \( $options->{signature} ),
'silent' => \( $options->{silent} ),
'dry-run' => \( $options->{dryrun} ),
'description=s' => \( $options->{description} ),
'author=s' => \( $options->{author} ),
'email=s' => \( $options->{email} ),
'path=s' => \( $options->{path} ),
'current' => \( $options->{current} ),
help => \&__pod2usage,
version => \&__version
);
# Set members
$self->{options} = $options;
# Set module name
&__pod2usage unless @ARGV;
$self->{module_name} = pop @ARGV;
$self->{module_name} =~ s/\.pm$//g;
# Set description
$self->{description} = $self->{options}->{description}
if $self->{options}->{description};
# Set user status
$self->{author} =
$self->{options}->{author} ? $self->{options}->{author}
: $self->{author} ? $self->{author}
: undef;
$self->{email} =
$self->{options}->{email} ? $self->{options}->{email}
: $self->{email} ? $self->{email}
( run in 0.973 second using v1.01-cache-2.11-cpan-13bb782fe5a )