Refactor FileHash to expect named arguments

This commit is contained in:
Dan Church 2023-07-20 13:04:52 -05:00
parent 31fe372e09
commit 15c466e581
Signed by: h3xx
GPG key ID: EA2BF379CD2CDBD0
2 changed files with 5 additions and 12 deletions

View file

@ -22,16 +22,9 @@ sub new {
} }
sub add { sub add {
my $self = shift; my ($self, %args) = @_;
my (@files, $callback); my @files = @{$args{files}};
if (ref $_[0] eq 'HASH') { my $callback = $args{callback};
# Called method like { files => [] }
my %opts = %{$_[0]};
@files = @{$opts{files}};
$callback = $opts{callback};
} else {
@files = @_;
}
foreach my $file (@files) { foreach my $file (@files) {
unless (ref $file eq 'Directory::Simplify::File') { unless (ref $file eq 'Directory::Simplify::File') {
$file = Directory::Simplify::File->new($file); $file = Directory::Simplify::File->new($file);

View file

@ -230,10 +230,10 @@ MAIN: {
} }
}; };
} }
$filehash->add({ $filehash->add(
files => \@files, files => \@files,
callback => $cb, callback => $cb,
}); );
print STDERR "done.\n" print STDERR "done.\n"
if $verbose; if $verbose;