Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert many subroutines to use signatures #708

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Revision history for {{$dist->name}}

{{$NEXT}}

6.026 2022-05-29 15:06:05-04:00 America/New_York (TRIAL RELEASE)
- use subroutine signatures throughout

6.025 2022-05-28 11:55:35-04:00 America/New_York
- eliminate use of multidimensional array emulation

Expand Down
54 changes: 15 additions & 39 deletions lib/Dist/Zilla.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ has version => (
builder => '_build_version',
);

sub _build_name {
my ($self) = @_;

sub _build_name ($self) {
my $name;
for my $plugin (@{ $self->plugins_with(-NameProvider) }) {
next unless defined(my $this_name = $plugin->provide_name);
Expand All @@ -104,9 +102,7 @@ sub _build_name {
$name;
}

sub _build_version {
my ($self) = @_;

sub _build_version ($self) {
my $version = $self->_version_override;

for my $plugin (@{ $self->plugins_with(-VersionProvider) }) {
Expand Down Expand Up @@ -157,9 +153,7 @@ has release_status => (
builder => '_build_release_status',
);

sub _build_release_status {
my ($self) = @_;

sub _build_release_status ($self) {
# environment variables override completely
return $self->_release_status_from_env if $self->_release_status_from_env;

Expand Down Expand Up @@ -190,8 +184,7 @@ has _release_status_from_env => (
builder => '_build_release_status_from_env',
);

sub _build_release_status_from_env {
my ($self) = @_;
sub _build_release_status_from_env ($self) {
return $ENV{RELEASE_STATUS} if $ENV{RELEASE_STATUS};
return $ENV{TRIAL} ? 'testing' : '';
}
Expand Down Expand Up @@ -328,9 +321,7 @@ has license => (
},
);

sub _build_license {
my ($self) = @_;

sub _build_license ($self) {
my $license_class = $self->_license_class;
my $copyright_holder = $self->_copyright_holder;
my $copyright_year = $self->_copyright_year;
Expand Down Expand Up @@ -498,8 +489,7 @@ has files => (
default => sub { [] },
);

sub prune_file {
my ($self, $file) = @_;
sub prune_file ($self, $file) {
my @files = @{ $self->files };

for my $i (0 .. $#files) {
Expand Down Expand Up @@ -549,9 +539,8 @@ has _override_is_trial => (
default => 0,
);

sub _build_is_trial {
my ($self) = @_;
return $self->release_status =~ /\A(?:testing|unstable)\z/ ? 1 : 0;
sub _build_is_trial ($self) {
return $self->release_status =~ /\A(?:testing|unstable)\z/ ? 1 : 0;
}

=attr plugins
Expand Down Expand Up @@ -587,9 +576,7 @@ has distmeta => (
builder => '_build_distmeta',
);

sub _build_distmeta {
my ($self) = @_;

sub _build_distmeta ($self) {
require CPAN::Meta::Merge;
my $meta_merge = CPAN::Meta::Merge->new(default_version => 2);
my $meta = {};
Expand Down Expand Up @@ -655,8 +642,7 @@ has prereqs => (

=cut

sub plugin_named {
my ($self, $name) = @_;
sub plugin_named ($self, $name) {
my $plugin = first { $_->plugin_name eq $name } @{ $self->plugins };

return $plugin if $plugin;
Expand All @@ -673,9 +659,7 @@ dash is replaced with "Dist::Zilla::Role::"

=cut

sub plugins_with {
my ($self, $role) = @_;

sub plugins_with ($self, $role) {
$role =~ s/^-/Dist::Zilla::Role::/;
my $plugins = [ grep { $_->does($role) } @{ $self->plugins } ];

Expand All @@ -693,9 +677,7 @@ found, an exception will be raised.

=cut

sub find_files {
my ($self, $finder_name) = @_;

sub find_files ($self, $finder_name) {
$self->log_fatal("no plugin named $finder_name found")
unless my $plugin = $self->plugin_named($finder_name);

Expand All @@ -705,9 +687,7 @@ sub find_files {
$plugin->find_files;
}

sub _check_dupe_files {
my ($self) = @_;

sub _check_dupe_files ($self) {
my %files_named;
my @dupes;
for my $file (@{ $self->files }) {
Expand All @@ -731,9 +711,7 @@ sub _check_dupe_files {
Carp::croak("aborting; duplicate files would be produced");
}

sub _write_out_file {
my ($self, $file, $build_root) = @_;

sub _write_out_file ($self, $file, $build_root) {
# Okay, this is a bit much, until we have ->debug. -- rjbs, 2008-06-13
# $self->log("writing out " . $file->name);

Expand Down Expand Up @@ -806,9 +784,7 @@ stash (from the user's global configuration).

=cut

sub stash_named {
my ($self, $name) = @_;

sub stash_named ($self, $name) {
return $self->_local_stashes->{ $name } if $self->_local_stashes->{$name};
return $self->_global_stashes->{ $name };
}
Expand Down
15 changes: 4 additions & 11 deletions lib/Dist/Zilla/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use namespace::autoclean;

$Carp::Internal{'Module::Runtime'} = 1;

sub global_opt_spec {
my ($self) = @_;

sub global_opt_spec ($self) {
return (
[ "verbose|v", "log additional output" ],
[ "verbose-plugin|V=s@", "log additional output from some plugins only" ],
Expand All @@ -25,9 +23,7 @@ sub global_opt_spec {
);
}

sub _build_global_stashes {
my ($self) = @_;

sub _build_global_stashes ($self) {
return $self->{__global_stashes__} if $self->{__global_stashes__};

# tests shouldn't depend on the user's configuration
Expand Down Expand Up @@ -100,8 +96,7 @@ been constructed, one will be by calling C<< Dist::Zilla->from_config >>.

=cut

sub chrome {
my ($self) = @_;
sub chrome ($self) {
require Dist::Zilla::Chrome::Term;

return $self->{__chrome__} if $self->{__chrome__};
Expand All @@ -119,9 +114,7 @@ sub chrome {
return $self->{__chrome__};
}

sub zilla {
my ($self) = @_;

sub zilla ($self) {
require Dist::Zilla::Dist::Builder;

return $self->{'' . __PACKAGE__}{zilla} ||= do {
Expand Down
8 changes: 2 additions & 6 deletions lib/Dist/Zilla/App/Command/add.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ sub opt_spec {
# [ 'module|m=s@', 'module(s) to create; may be given many times' ],
}

sub validate_args {
my ($self, $opt, $args) = @_;

sub validate_args ($self, $opt, $args) {
require MooseX::Types::Perl;

$self->usage_error('dzil add takes one or more arguments') if @$args < 1;
Expand All @@ -46,9 +44,7 @@ sub validate_args {
}
}

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
my $zilla = $self->zilla;
my $dist = $zilla->name;

Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/authordeps.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ sub opt_spec {
);
}

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
require Dist::Zilla::Path;
require Dist::Zilla::Util::AuthorDeps;

Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ necessary, the directory will be created. An archive will not be created.

=cut

sub execute {
my ($self, $opt, $args) = @_;

sub execute ($self, $opt, $args) {
if ($opt->in) {
require Path::Tiny;
die qq{using "--in ." would destroy your working directory!\n}
Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/clean.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ Nothing is removed; instead, everything that would be removed will be listed.

sub abstract { 'clean up after build, test, or install' }

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
$self->zilla->clean($opt->dry_run);
}

Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/install.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ Dist::Zilla.

=cut

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
$self->zilla->install({
$opt->install_command
? (install_command => [ $opt->install_command ])
Expand Down
15 changes: 4 additions & 11 deletions lib/Dist/Zilla/App/Command/listdeps.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ sub opt_spec {
[ 'omit-core=s', 'Omit dependencies that are shipped with the specified version of perl' ],
}

sub prereqs {
my ($self, $zilla) = @_;

sub prereqs ($self, $zilla) {
$_->before_build for @{ $zilla->plugins_with(-BeforeBuild) };
$_->gather_files for @{ $zilla->plugins_with(-FileGatherer) };
$_->set_file_encodings for @{ $zilla->plugins_with(-EncodingProvider) };
Expand All @@ -96,8 +94,7 @@ sub prereqs {
my @phases = qw/configure build test runtime develop/;
my @relationships = qw/requires recommends suggests/;

sub filter_core {
my ($prereqs, $core_version) = @_;
sub filter_core ($prereqs, $core_version) {
$core_version = sprintf '%7.6f', $core_version if $core_version >= 5.010;
$prereqs = $prereqs->clone if $prereqs->is_finalized;
require Module::CoreList;
Expand All @@ -113,9 +110,7 @@ sub filter_core {
return $prereqs;
}

sub extract_dependencies {
my ($self, $zilla, $phases, $opt) = @_;

sub extract_dependencies ($self, $zilla, $phases, $opt) {
my $prereqs = $self->prereqs($zilla);
$prereqs = filter_core($prereqs, $opt->omit_core) if $opt->omit_core;

Expand Down Expand Up @@ -149,9 +144,7 @@ sub extract_dependencies {
return map { $_ => $versions->{$_} } @required;
}

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
$self->app->chrome->logger->mute;

my @phases = qw(build test configure runtime);
Expand Down
8 changes: 2 additions & 6 deletions lib/Dist/Zilla/App/Command/new.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ sub opt_spec {
# [ 'module|m=s@', 'module(s) to create; may be given many times' ],
}

sub validate_args {
my ($self, $opt, $args) = @_;

sub validate_args ($self, $opt, $args) {
require MooseX::Types::Perl;

$self->usage_error('dzil new takes exactly one argument') if @$args != 1;
Expand All @@ -71,9 +69,7 @@ sub validate_args {
$args->[0] = $name;
}

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
my $dist = $arg->[0];

require Dist::Zilla::Dist::Minter;
Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/nop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ sub description {
"It is sometimes useful for diagnostic purposes."
}

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
$self->zilla;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ sub opt_spec {
[ 'jobs|j=i' => 'number of parallel test jobs to run' ],
}

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
my $zilla;
{
# isolate changes to RELEASE_STATUS to zilla construction
Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/run.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ sub usage_desc {
return '%c run %o [ command [ arg1 arg2 ... ] ]';
}

sub execute {
my ($self, $opt, $args) = @_;

sub execute ($self, $opt, $args) {
unless (@$args) {
my $envname = $^O eq 'MSWin32' ? 'COMSPEC' : 'SHELL';
unless ($ENV{$envname}) {
Expand Down
8 changes: 2 additions & 6 deletions lib/Dist/Zilla/App/Command/setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ sub description {
"a basic Dist::Zilla configuration in ~/.dzil/config.ini"
}

sub validate_args {
my ($self, $opt, $args) = @_;

sub validate_args ($self, $opt, $args) {
$self->usage_error('too many arguments') if @$args != 0;
}

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
my $chrome = $self->app->chrome;

require Dist::Zilla::Util;
Expand Down
4 changes: 1 addition & 3 deletions lib/Dist/Zilla/App/Command/smoke.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ This will run the test suite with AUTHOR_TESTING=1

sub abstract { 'smoke your dist' }

sub execute {
my ($self, $opt, $arg) = @_;

sub execute ($self, $opt, $arg) {
local $ENV{RELEASE_TESTING} = 1 if $opt->release;
local $ENV{AUTHOR_TESTING} = 1 if $opt->author;
local $ENV{AUTOMATED_TESTING} = 1 if $opt->automated;
Expand Down
Loading