Skip to content

Commit

Permalink
avoid use of @_ where practical
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Jun 7, 2020
1 parent 535d759 commit 2d3b05f
Show file tree
Hide file tree
Showing 98 changed files with 376 additions and 843 deletions.
83 changes: 26 additions & 57 deletions lib/Dist/Zilla.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,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 @@ -103,9 +101,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 @@ -156,9 +152,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,7 +184,6 @@ has _release_status_from_env => (
);

sub _build_release_status_from_env {
my ($self) = @_;
return $ENV{RELEASE_STATUS} if $ENV{RELEASE_STATUS};
return $ENV{TRIAL} ? 'testing' : '';
}
Expand All @@ -206,9 +199,7 @@ has abstract => (
is => 'rw',
isa => 'Str',
lazy => 1,
default => sub {
my ($self) = @_;

default => sub ($self, @) {
unless ($self->main_module) {
die "no abstract given and no main_module found; make sure your main module is in ./lib\n";
}
Expand Down Expand Up @@ -255,9 +246,7 @@ has main_module => (
isa => 'Dist::Zilla::Role::File',
lazy => 1,
init_arg => undef,
default => sub {
my ($self) = @_;

default => sub ($self, @) {
my $file;
my $guess;

Expand Down Expand Up @@ -327,9 +316,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 @@ -403,8 +390,8 @@ has _license_class => (
lazy => 1,
init_arg => 'license',
clearer => '_clear_license_class',
default => sub {
my $stash = $_[0]->stash_named('%Rights');
default => sub ($self, @) {
my $stash = $self->stash_named('%Rights');
$stash && return $stash->license_class;
return;
}
Expand All @@ -416,8 +403,8 @@ has _copyright_holder => (
lazy => 1,
init_arg => 'copyright_holder',
clearer => '_clear_copyright_holder',
default => sub {
return unless my $stash = $_[0]->stash_named('%Rights');
default => sub ($self, @) {
return unless my $stash = $self->stash_named('%Rights');
$stash && return $stash->copyright_holder;
return;
}
Expand All @@ -429,15 +416,15 @@ has _copyright_year => (
lazy => 1,
init_arg => 'copyright_year',
clearer => '_clear_copyright_year',
default => sub {
default => sub ($self, @) {
# Oh man. This is a terrible idea! I mean, what if by the code gets run
# around like Dec 31, 23:59:59.9 and by the time the default gets called
# it's the next year but the default was already set up? Oh man. That
# could ruin lives! I guess we could make this a sub to defer the guess,
# but think of the performance hit! I guess we'll have to suffer through
# this until we can optimize the code to not take .1s to run, right? --
# rjbs, 2008-06-13
my $stash = $_[0]->stash_named('%Rights');
my $stash = $self->stash_named('%Rights');
my $year = $stash && $stash->copyright_year;
return( $year // (localtime)[5] + 1900 );
}
Expand All @@ -463,9 +450,7 @@ has authors => (
lazy => 1,
traits => [ 'Array' ],
reader => '_authors',
default => sub {
my ($self) = @_;

default => sub ($self) {
if (my $stash = $self->stash_named('%User')) {
return [ $stash->authors ];
}
Expand Down Expand Up @@ -515,8 +500,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 @@ -566,9 +550,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 @@ -622,9 +605,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 @@ -690,8 +671,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 @@ -708,9 +688,7 @@ 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 @@ -737,9 +715,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 @@ -749,9 +725,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 @@ -775,9 +749,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 @@ -814,13 +786,12 @@ has logger => (
isa => 'Log::Dispatchouli::Proxy', # could be duck typed, I guess
lazy => 1,
handles => [ qw(log log_debug log_fatal) ],
default => sub {
$_[0]->chrome->logger->proxy({ proxy_prefix => '[DZ] ' })
default => sub ($self, @) {
$self->chrome->logger->proxy({ proxy_prefix => '[DZ] ' })
},
);

around dump_config => sub {
my ($orig, $self) = @_;
around dump_config => sub ($orig, $self) {
my $config = $self->$orig;
$config->{is_trial} = $self->is_trial;
return $config;
Expand Down Expand Up @@ -850,9 +821,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 Try::Tiny;

$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: 3 additions & 5 deletions lib/Dist/Zilla/App/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ been constructed, one will be by calling C<< Dist::Zilla->from_config >>.
=cut

sub zilla {
return $_[0]->app->zilla;
}
sub zilla ($self) { $self->app->zilla }

=method log
This method calls the C<log> method of the application's chrome.
=cut

sub log {
$_[0]->app->chrome->logger->log($_[1]);
sub log ($self, $what) {
$self->app->chrome->logger->log($what);
}

1;
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 @@ -34,9 +34,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 @@ -47,9 +45,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 @@ -34,9 +34,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 @@ -88,9 +88,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 @@ -32,9 +32,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 @@ -45,9 +45,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
Loading

0 comments on commit 2d3b05f

Please sign in to comment.