Ado
view release on metacpan or search on metacpan
lib/Ado/Build.pm view on Meta::CPAN
my $self = shift;
return $self->_uninstall('dry-run');
}
sub ACTION_build {
my $self = shift;
#Make sure *log files are empty before moving them to blib
_empty_log_files('log');
#Do other interventions before the real build...
$self->SUPER::ACTION_build;
return;
}
sub ACTION_test {
my $self = shift;
#Custom functionality before test
$self->_process_custom_files(catdir('blib', 'etc'), catdir('blib', 'log'))
if -d 'blib';
$self->_process_custom_files('etc', 'log');
$self->SUPER::ACTION_test;
return;
}
sub ACTION_dist {
my $self = shift;
#Make sure *log files are empty before including them into the distro
_empty_log_files('log');
#Do other interventions before the real dist..
$self->SUPER::ACTION_dist;
return;
}
sub ACTION_install {
my $self = shift;
#Custom functionality before installation
#here...
#TODO: Think about what to do with *.conf and *.sqlite files in case of upgrade!!!
#TODO: (upgrade)rotate logs - archive existing log files before emptying.
$self->SUPER::ACTION_install;
#Custom functionality after installation
$self->_process_custom_files($self->install_path('etc'), $self->install_path('log'));
return;
}
sub _process_custom_files {
my ($self, $etc_dir, $log_dir) = @_;
#make some files writable and/or readable only by the user that runs the application
my $ro = oct('0400');
my $rw = oct('0600');
for my $asset (
qw(ado.conf plugins/routes.conf plugins/auth.conf plugins/markdown_renderer.conf))
{
_chmod($ro, catfile($etc_dir, $asset));
}
_chmod($rw, catfile($etc_dir, 'ado.sqlite'));
#Make sure *log files are existing and empty
_empty_log_files($log_dir);
for my $asset (qw(development production)) {
_chmod($rw, catfile($log_dir, "$asset.log"));
}
return;
}
sub _chmod {
my ($mode, $file) = @_;
return chmod($mode, $file)
|| Carp::carp("Could not change mode for $file: $!");
}
sub ACTION_perltidy {
my $self = shift;
eval { require Perl::Tidy } || do {
$self->log_warn(
"Perl::Tidy is not installed$/" . "Please install it and rerun ./Build perltidy$/");
return;
};
my @files;
for my $dir ($self->PERL_DIRS) {
my $dir_files = $self->rscan_dir($dir);
for my $file (@$dir_files) {
push @files, $file
if -f $file && $file =~ m{(\.pl|/ado|\.pm|ado.*?\.conf|\.t)$}x;
}
}
if ($self->verbose) {
say join($/, @files) . "$/perltidy-ing " . @files . " files...";
}
#We use ./.perltidyrc for all arguments
Perl::Tidy::perltidy(argv => [@files]);
foreach my $file (@{$self->rscan_dir($self->base_dir)}) {
unlink($file) if $file =~ /\.bak$/;
}
say "perltidy-ed distribution.";
return;
}
sub ACTION_submit {
my $self = shift;
#$self->depends_on("perltidy");
say "TODO: commit and push after tidying and testing and who knows what";
return;
}
#Empties log files in a given directory.
sub _empty_log_files {
(my ($log_dir) = @_) || Carp::croak('Please provide $log_dir');
open my $logd, ">", "$log_dir/development.log" || Carp::croak $!;
close $logd;
open my $logp, ">", "$log_dir/production.log" || Carp::croak $!;
close $logp;
return;
}
sub do_create_readme {
my $self = shift;
if ($self->dist_version_from =~ /Ado\.pm$/) {
#Create README from Ado::Manual.pod
require Pod::Text;
my $readme_from = catfile('lib', 'Ado', 'Manual.pod');
my $parser = Pod::Text->new(sentence => 0, indent => 2, width => 76);
$parser->parse_from_file($readme_from, 'README');
( run in 1.205 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )