Genealogy-Obituary-Lookup
view release on metacpan or search on metacpan
lib/Genealogy/Obituary/Lookup.pm view on Meta::CPAN
# ---------------------------------------------------------------------------
# Purpose: Builds the source URL for an obituary record.
# Entry: $obit â hashref with 'source' (M/F/L), 'page', and optionally
# 'newspaper' (required for source 'L').
# Exit: String URL.
sub _create_url
{
# Enforce privacy: only code within this package may call _create_url.
Carp::croak("_create_url() is a private method of " . __PACKAGE__)
unless (caller)[0] eq __PACKAGE__;
my $obit = shift;
my $page = $obit->{'page'};
my $source = $obit->{'source'};
Carp::croak(__PACKAGE__->_i18n('err_no_page', {package => __PACKAGE__}))
unless defined $page;
Carp::croak(__PACKAGE__->_i18n('err_no_source', {package => __PACKAGE__, page => $page}))
unless defined $source;
t/function.t view on Meta::CPAN
my $obj = _new_obj();
throws_ok { $obj->search(last => 'Smith') }
qr/Can't open the obituaries database/,
'search() croaks with err_no_obituaries when the DB handle is undef';
};
# ---------------------------------------------------------------------------
# Subtest group: _create_url() â privacy enforcement and URL construction
#
# _create_url() enforces the (caller)[0] eq __PACKAGE__ guard, so we can only
# verify its logic indirectly by driving search() with controlled mock rows.
# ---------------------------------------------------------------------------
subtest '_create_url() â direct external call is refused' => sub {
throws_ok {
Genealogy::Obituary::Lookup::_create_url({ source => 'M', page => 1 })
} qr/private method/,
'_create_url() croaks when invoked from outside the package';
};
subtest '_create_url() â source L: newspaper URL takes precedence over page' => sub {
( run in 1.059 second using v1.01-cache-2.11-cpan-d80b1682f3f )