App-Perl-Module-CopyrightYears
view release on metacpan or search on metacpan
CopyrightYears.pm view on Meta::CPAN
# Change copyright years in LICENSE file.
my @licenses = $self->_files('.', 'LICENSE*');
foreach my $license (@licenses) {
if (defined $license && -r $license) {
my @license = slurp($license);
my $opts_hr = {
'prefix_glob' => '.*\(c\)\s+',
};
my $update_file = 0;
foreach (my $i = 0; $i < @license; $i++) {
my $updated = update_years($license[$i], $opts_hr,
$self->{'_opts'}->{'y'});
if ($updated) {
$license[$i] = $updated;
$update_file = 1;
}
}
if ($update_file) {
barf($license, (join '', @license));
}
}
}
# Look for scripts with copyright years.
if (-d 'bin') {
my @bin = $self->_files('bin', '*');
# Dump tools in debug mode.
if ($self->{'_opts'}->{'d'}) {
print "Found scripts:\n";
print map { '- '.$_."\n"; } @bin;
}
# Update years.
foreach my $bin (@bin) {
$self->_update_pod($bin);
}
}
return 0;
}
sub _files {
my ($self, $dir, @file_globs) = @_;
my $rule = File::Find::Rule->new;
my @pm = $rule->or(
$rule->new->directory->name('t')->prune->discard,
$rule->new->directory->name('inc')->prune->discard,
$rule->new->directory->name('blib')->prune->discard,
$rule->new,
)->name(@file_globs)->in($dir);
return @pm;
}
sub _update_pod {
my ($self, $file) = @_;
my @sections = split m/,/, $self->{'_opts'}->{'s'};
my $cy = Pod::CopyrightYears->new(
$self->{'_opts'}->{'d'} ? ('debug' => 1) : (),
'pod_file' => $file,
'section_names' => \@sections,
);
$cy->change_years($self->{'_opts'}->{'y'});
barf($file, $cy->pod);
return;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
App::Perl::Module::CopyrightYears - Base class for perl-module-copyright-years tool.
=head1 SYNOPSIS
use App::Perl::Module::CopyrightYears;
my $app = App::Perl::Module::CopyrightYears->new;
my $exit_code = $app->run;
=head1 METHODS
=head2 C<new>
my $app = App::Perl::Module::CopyrightYears->new;
Constructor.
Returns instance of object.
=head2 C<run>
my $exit_code = $app->run;
Run.
Returns 1 for error, 0 for success.
=head1 ERRORS
new():
From Class::Utils::set_params():
Unknown parameter '%s'.
=head1 EXAMPLE
=for comment filename=print_help.pl
use strict;
use warnings;
( run in 1.251 second using v1.01-cache-2.11-cpan-bbcb1afb8fc )