diff --git a/MANIFEST b/MANIFEST index 5b63595..84782f9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -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 @@ -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 diff --git a/lib/Genealogy/ObituaryDailyTimes.pm b/lib/Genealogy/ObituaryDailyTimes.pm index 04f2ede..376c7b4 100644 --- a/lib/Genealogy/ObituaryDailyTimes.pm +++ b/lib/Genealogy/ObituaryDailyTimes.pm @@ -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; diff --git a/t/carp.t b/t/carp.t index 6c63ccb..8dd9f16 100644 --- a/t/carp.t +++ b/t/carp.t @@ -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(); diff --git a/t/critic.t b/t/critic.t index b954bf3..0ecea67 100644 --- a/t/critic.t +++ b/t/critic.t @@ -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(); diff --git a/t/pod-snippets.t b/t/pod-snippets.t new file mode 100644 index 0000000..ccf91ec --- /dev/null +++ b/t/pod-snippets.t @@ -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(); diff --git a/t/pod-spelling.t b/t/pod-spelling.t index 5aa2f56..5199742 100644 --- a/t/pod-spelling.t +++ b/t/pod-spelling.t @@ -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(); - all_pod_files_spelling_ok(); - } -} else { - plan(skip_all => 'Author tests not required for installation'); -} +Test::Spelling->import(); + +add_stopwords(); +all_pod_files_spelling_ok(); __END__ CPANTS diff --git a/t/snippets.t b/t/snippets.t deleted file mode 100644 index 4f07d99..0000000 --- a/t/snippets.t +++ /dev/null @@ -1,24 +0,0 @@ -#!perl -wT - -use strict; -use warnings; -use File::Spec; -use Test::Most; - -if($ENV{AUTHOR_TESTING}) { - eval 'use Test::Pod::Snippets'; - - if($@) { - plan(skip_all => 'Test::Pod::Snippets required for testing POD code snippets'); - } else { - my $tps = Test::Pod::Snippets->new(); - - my @modules = qw/ Genealogy::ObituaryDailyTimes /; - - $tps->runtest(module => $_, testgroup => 1) for @modules; - - done_testing(); - } -} else { - plan(skip_all => 'Author tests not required for installation'); -} diff --git a/t/strict.t b/t/strict.t index 458516a..6223d49 100644 --- a/t/strict.t +++ b/t/strict.t @@ -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');