Module-Provision
view release on metacpan or search on metacpan
lib/Module/Provision/TraitFor/AddingFiles.pm view on Meta::CPAN
return $_[ 0 ]->loc( 'One-line description of the programs purpose' );
};
my $_get_target = sub {
my ($self, $dir, $f) = @_;
my $car = $self->next_argv or throw Unspecified, [ 'Target' ];
my $abstract = $self->next_argv
|| ($self->method eq 'program' ? $self->$_program_abstract
: $self->module_abstract );
$self->project; # Force evaluation of lazy attribute
my $target = $self->$dir->catfile( $f ? $f->( $car ) : $car );
$target->perms( $self->perms )->assert_filepath;
if ($self->method eq 'module') { $self->stash->{module } = $car }
elsif ($self->method eq 'program') { $self->stash->{program_name} = $car }
$self->method ne 'test' and $self->stash->{abstract} = $abstract;
return $target;
};
my $_add_test_script = sub {
my $self = shift; my $target = $self->$_get_target( 'testdir' );
$self->quiet or $self->output( 'Adding new test' );
$target = $self->render_template( '10test_script.t', $target );
$self->add_to_vcs( $target, 'test' );
return OK;
};
# Public methods
sub module : method {
my $self = shift; my $target = $self->$_get_target( 'libdir', \&classfile );
$self->quiet or $self->output( 'Adding new module' );
$target = $self->render_template( 'perl_module.pm', $target );
$self->add_to_vcs( $target, 'module' );
return OK;
}
sub program : method {
my $self = shift; my $target = $self->$_get_target( 'binsdir' );
$self->quiet or $self->output( 'Adding new program' );
$target = $self->render_template( 'perl_program.pl', $target );
chmod $self->exec_perms, $target->pathname;
$self->add_to_vcs( $target, 'program' );
return OK;
}
sub test : method {
my $self = shift; my $flags = $self->cmd_line_flags; $flags->{test} = TRUE;
return $flags->{release} ? $self->release : $self->$_add_test_script;
}
sub update_file : method {
my $self = shift;
my $target = $self->next_argv or throw Unspecified, [ 'target' ];
my $index = {};
for my $t (map { my $k = $_->[ 0 ]; my $v = $_->[ 1 ];
$_->[ 1 ] = $v->relative( $self->appldir ); $_ }
map { my $k = $_->[ 0 ]; my $v = $_->[ 1 ];
$v->is_dir and $_->[ 1 ] = $v->catfile( $k ); $_ }
map { $self->expand_tuple( $_ ) } @{ $self->template_list } ) {
$index->{ $t->[ 1 ]->pathname } = $t->[ 0 ];
}
exists $index->{ $target }
or throw 'File [_1] not in template map', [ $target ];
my $source = $self->template_dir->catfile( $index->{ $target } );
$source->exists or throw 'File [_1] not found', [ $source ];
$source->copy( $target );
return OK;
}
1;
__END__
=pod
=encoding utf8
=head1 Name
Module::Provision::TraitFor::AddingFiles - Adds additional files to the project
=head1 Synopsis
use Moose;
extends 'Module::Provision::Base';
with 'Module::Provision::TraitFor::AddingFiles';
=head1 Description
Adds additional modules, programs, and tests to the project
=head1 Configuration and Environment
Requires the following attributes to be defined in the consuming
class; C<add_to_vcs>, C<appldir>, C<binsdir>, C<exec_perms>, C<libdir>,
C<module_abstract>, C<render_template>, C<stash>, and C<testdir>
Modifies the C<generate_metadata> method. If C<generate_metadata> returns
a pathname and the file exists it is added to the VCS
Defines no attributes
=head1 Subroutines/Methods
=head2 module - Create a new Perl module file
( run in 0.674 second using v1.01-cache-2.11-cpan-98e64b0badf )