Module-Make
view release on metacpan or search on metacpan
lib/Module/Make.pm view on Meta::CPAN
package Module::Make;
use 5.006001;
use strict;
use warnings;
use Module::Make::Base -base;
our $VERSION = '0.01';
const maker_class => 'Module::Make::Maker';
field 'src_dir';
sub import {
my $class = shift;
my $flag = shift || '';
my $package = caller;
no strict 'refs';
if ($flag eq 'new') {
$class->new->new_environment(@ARGV);
exit;
}
elsif ($flag eq 'update') {
$class->new->update_environment(@ARGV);
exit;
}
}
sub new_environment {
my $self = shift;
# Check to make sure the cli args are sane
$self->sanity_check_new_cli_args(@_);
# Prompt user to create the target directory
$self->get_src_dir;
# Make appropriate directories
$self->make_src_dir;
# Change to src dir
$self->chdir_src;
# Write a `config.yaml` file.
$self->create_config_yaml_file;
# Generate mininal Makefile
$self->create_new_makefile;
# sleep 1
# touch .stamps/new_environment
# tell user to now edit the `config.yaml` file
}
sub update_environment {
die "Can't update existing Module::Make environment yet";
}
sub sanity_check_new_cli_args {
my $self = shift;
my $dir = io->dir(shift || '.');
die "Unknown args '@_' to Module::Make=new\n" if @_;
$dir = $self->check_new_dir_path($dir);
$self->src_dir($dir);
}
sub get_src_dir {
my $self = shift;
my $dir = $self->src_dir;
return if $dir->exists;
while (1) {
return if $self->prompt_yn("Create $dir", 'Yn') eq 'y';
my $path = $self->prompt_path("Enter a new module dist path:");
$dir = io->dir($path);
$dir = $self->check_new_dir_path($dir);
}
}
sub make_src_dir {
my $self = shift;
my $dir = $self->src_dir;
if ($dir->exists) {
print "Using '$dir' for new environment.\n";
return;
}
print "Creating $dir \n";
$dir->assert->open;
$dir->close;
}
sub chdir_src {
my $self = shift;
my $dir = $self->src_dir;
$dir->chdir;
}
sub create_config_yaml_file {
require Config;
no warnings 'once';
my $self = shift;
io('config.yaml')->print(<<"...");
# Generated by ${\ ref($self) } on ${\ scalar(localtime)}.
#
# Please edit these values appropriately and then run `make`.
maker_class: ${\ $self->maker_class}
dist_name: ${\ $self->guess_dist_name}
dist_version: 0.00
perl_path: $Config::Config{perlpath}
target_base: ..
...
}
sub create_new_makefile {
my $self = shift;
( run in 2.160 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )