Skip to content

Commit

Permalink
Latest _get_params from CGI::Info
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Dec 27, 2024
1 parent b56fc52 commit ade6fdf
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 64 deletions.
3 changes: 2 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ MANIFEST.SKIP
README.md
t/00-load.t
t/10-new.t
t/30-basics.t
t/carp.t
t/comment-spelling.t
t/coverage.t
Expand All @@ -24,10 +25,10 @@ t/noopentickets.t
t/noplan.t
t/obituaries.t
t/pod-cm.t
t/pod-snippets.t
t/pod-spelling.t
t/pod-synopsis.t
t/pod.t
t/snippets.t
t/strict.t
t/unused.t
t/vars.t
Expand Down
37 changes: 20 additions & 17 deletions lib/Genealogy/ObituaryDailyTimes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,35 @@ sub _create_url {
}

# Helper routine to parse the arguments given to a function,
# Processes arguments passed to methods and ensures they are in a usable format,
# allowing the caller to call the function in anyway that they want
# e.g. foo('bar'), foo(arg => 'bar'), foo({ arg => 'bar' }) all mean the same
# when called _get_params('arg', @_);
sub _get_params
{
my $self = shift;
shift; # Discard the first argument (typically $self)
my $default = shift;

my %rc;
# Directly return hash reference if the first parameter is a hash reference
return $_[0] if(ref $_[0] eq 'HASH');

if(ref($_[0]) eq 'HASH') {
%rc = %{$_[0]};
} elsif((scalar(@_) % 2) == 0) {
my %rc;
my $num_args = scalar @_;

# Populate %rc based on the number and type of arguments
if(($num_args == 1) && (defined $default)) {
# %rc = ($default => shift);
return { $default => shift };
} elsif($num_args == 1) {
Carp::croak('Usage: ', __PACKAGE__, '->', (caller(1))[3], '()');
} elsif(($num_args == 0) && (defined($default))) {
Carp::croak('Usage: ', __PACKAGE__, '->', (caller(1))[3], "($default => \$val)");
} elsif(($num_args % 2) == 0) {
%rc = @_;
} elsif(scalar(@_) == 1) {
if(defined($default)) {
$rc{$default} = shift;
} else {
my @c = caller(1);
my $func = $c[3]; # calling function name
Carp::croak('Usage: ', __PACKAGE__, "->$func($default => " . '$val)');
}
} elsif((scalar(@_) == 0) && defined($default)) {
my @c = caller(1);
my $func = $c[3]; # calling function name
Carp::croak('Usage: ', __PACKAGE__, "->$func($default => " . '$val)');
} elsif($num_args == 0) {
return;
} else {
Carp::croak('Usage: ', __PACKAGE__, '->', (caller(1))[3], '()');
}

return \%rc;
Expand Down
2 changes: 1 addition & 1 deletion t/carp.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SKIP: {

my $search = new_ok('Genealogy::ObituaryDailyTimes' => [ directory => 'lib/Genealogy/ObituaryDailyTimes/data' ]);

does_carp_that_matches(sub { my @empty = $search->search(); }, qr/^Value for 'last' is mandatory/);
does_croak_that_matches(sub { my @empty = $search->search(); }, qr/^Usage: .*last/);
does_carp_that_matches(sub { my @empty = $search->search(last => undef); }, qr/^Value for 'last' is mandatory/);
does_carp_that_matches(sub { my @empty = $search->search({ last => undef }); }, qr/^Value for 'last' is mandatory/);
done_testing();
Expand Down
13 changes: 4 additions & 9 deletions t/critic.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

use strict;
use warnings;

use Test::DescribeMe qw(author);
use File::Spec;
use Test::Most;
use Test::Needs 'Test::Perl::Critic';
use English qw(-no_match_vars);

if($ENV{AUTHOR_TESTING}) {
eval 'use Test::Perl::Critic';

plan(skip_all => 'Test::Perl::Critic not installed; skipping') if $@;

all_critic_ok();
} else {
plan(skip_all => 'Author tests not required for installation');
}
Test::Perl::Critic::all_critic_ok();
14 changes: 14 additions & 0 deletions t/pod-snippets.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!perl -w

use strict;
use warnings;

use Test::DescribeMe qw(author);
use Test::Most;
use Test::Needs 'Test::Pod::Snippets';

my @modules = qw/ Genealogy::ObituaryDailyTimes /;
Test::Pod::Snippets->import();
Test::Pod::Snippets->new()->runtest(module => $_, testgroup => 1) for @modules;

done_testing();
17 changes: 6 additions & 11 deletions t/pod-spelling.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
use strict;
use warnings;

use Test::DescribeMe qw(author);
use Test::Most;
use Test::Needs 'Test::Spelling';

if($ENV{AUTHOR_TESTING}) {
eval 'use Test::Spelling';
if($@) {
plan(skip_all => 'Test::Spelling required for testing POD spelling');
} else {
add_stopwords(<DATA>);
all_pod_files_spelling_ok();
}
} else {
plan(skip_all => 'Author tests not required for installation');
}
Test::Spelling->import();

add_stopwords(<DATA>);
all_pod_files_spelling_ok();

__END__
CPANTS
Expand Down
24 changes: 0 additions & 24 deletions t/snippets.t

This file was deleted.

2 changes: 1 addition & 1 deletion t/strict.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ use Test::Needs 'Test::Strict';

Test::Strict->import();
all_perl_files_ok();
warnings_ok('lib/CGI/Info.pm');
warnings_ok('lib/Genealogy/ObituaryDailyTimes/obituaries.pm');

0 comments on commit ade6fdf

Please sign in to comment.