Bot-Net
view release on metacpan or search on metacpan
lib/Bot/Net/Script/Net.pm view on Meta::CPAN
( 'name=s' => 'name' );
}
=head2 run
Creates the bot net scaffoldering.
=cut
sub run {
my ($self, @args) = @_;
defined $self->{name}
or die "No bot net name given with required --name option.\n";
$self->prefix( $self->{name} );
# Split by - or :: and DWIM
my @path_comp = split /\-|::/, $self->prefix;
$self->mod_name( join '::', @path_comp );
$self->dist_name( join '-', @path_comp );
print "Creating new application $self->{name}\n";
$self->_make_directories;
$self->_install_botnet_binary;
$self->_write_makefile;
$self->_write_config_file;
$self->_create_log4perl_config_file;
}
sub _make_directories {
my $self = shift;
# Make the main directory
print "Creating directories...\n";
mkpath($self->dist_name, 1);
my @lib_dirs = split /::/, $self->mod_name;
my $lib_dir = File::Spec->catfile(@lib_dirs);
my @dirs = map {
s/__APP__/$lib_dir/;
File::Spec->catfile($self->dist_name, $_)
} $self->_directories;
mkpath(\@dirs, 1);
}
sub _install_botnet_binary {
my $self = shift;
my $bin = $FindBin::Bin;
my $script = basename($0);
# Get ready to copy
my $source_file = File::Spec->catfile($bin, $script);
my $dest_file = File::Spec->catfile($self->dist_name, 'bin', $script);
# Copy and make it executable
print "Copying in $dest_file...\n";
copy($source_file, $dest_file);
chmod 0555, $dest_file;
# If on a DOSish platform make bat file too
if (-e $source_file.'.bat') {
print "Copying in $dest_file.bat...\n";
copy($source_file.'.bat', $dest_file.'.bat');
chmod 0555, $dest_file.'.bat';
}
}
sub _write_makefile {
my $self = shift;
my $makefile = File::Spec->catfile($self->dist_name, 'Makefile.PL');
print "Creating $makefile...\n";
open my $makefh, '>', $makefile
or die "Cannot write $makefile: $!";
print $makefh <<"END_OF_MAKEFILE_PL";
use inc::Module::Install;
name '@{[$self->mod_name]}';
version '0.01';
requires 'Bot::Net' => '@{[$Bot::Net::VERSION]}';
WriteAll;
END_OF_MAKEFILE_PL
}
sub _write_config_file {
my $self = shift;
my $config_file = File::Spec->catfile($self->dist_name, 'etc/net.yml');
print "Creating $config_file...\n";
DumpFile($config_file, {
ApplicationClass => $self->mod_name,
ApplicationName => $self->mod_name,
});
}
sub _create_log4perl_config_file {
my $self = shift;
my $bin = $FindBin::Bin;
# Get ready to create
my $dest_file = File::Spec->catfile(
$self->dist_name, 'etc', 'log4perl.conf');
open my $log4perl, '>', $dest_file
or die "Could not write to $dest_file: $!";
print "Creating $dest_file...\n";
print $log4perl <<'END_OF_LOG4PERL_CONF';
log4perl.rootLogger=DEBUG, SCREEN
log4perl.appender.SCREEN=Log::Log4perl::Appender::Screen
log4perl.appender.SCREEN.stderr=0
log4perl.appender.SCREEN.layout=PatternLayout
log4perl.appender.SCREEN.layout.ConversionPattern=[%d] %c - %m%n
END_OF_LOG4PERL_CONF
}
sub _directories {
return qw{
bin
( run in 0.491 second using v1.01-cache-2.11-cpan-39bf76dae61 )