ObituaryDailyTimes.pm

filter: Statementstmt 82.3% 84 / 102 Branchbran 64.2% 27 / 42 Conditioncond 66.6% 6 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 14 / 14 Podpod 100% 2 / 2 totaltotal 77.1% 135 / 175 CC 26 SCAR 22.3
CC
26
Cov
76%
new
14.4
search
12.0
_create_url
10.0
CRAP 9.3
↑ Summary ObituaryDailyTimes/obituaries.pm »
1 package Genealogy::ObituaryDailyTimes;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Config::Abstraction;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Data::Reuse;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Module::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Genealogy::ObituaryDailyTimes::obituaries;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Params::Get;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶use constant URLS => {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 # 'M' => "https://mlarchives.rootsweb.com/listindexes/emails?listname=gen-obit&page=",
17 'M' => "https://wayback.archive-it.org/20669/20231102044925/https://mlarchives.rootsweb.com/listindexes/emails?listname=gen-obit&page=",
18 'F' => "https://www.freelists.org/post/obitdailytimes/Obituary-Daily-Times-",
19 5 };
20  
21 =head1 NAME
22  
23 Genealogy::ObituaryDailyTimes - Lookup an entry in the Obituary Daily Times
24  
25 =head1 VERSION
26  
27 Version 0.16
28  
29 =cut
30  
31 5 our $VERSION = '0.16';
32  
33 =head1 SYNOPSIS
34  
35 Looks up obituaries from the Obituary Daily Times and other places.
36  
37 use Genealogy::ObituaryDailyTimes;
38 my $info = Genealogy::ObituaryDailyTimes->new();
39 # ...
40  
41 =head1 SUBROUTINES/METHODS
42  
43 =head2 new
44  
45 Creates a Genealogy::ObituaryDailyTimes object.
46  
47 my $obits = Genealogy::ObituaryDailyTimes->new();
48  
49 Accepts the following optional arguments:
50  
51 =over 4
52  
53 =item * C<cache> - Passed to L<Database::Abstraction>
54  
55 =item * C<config_file>
56  
57 Points to a configuration file which contains the parameters to C<new()>.
58 The file can be in any common format including C<YAML>, C<XML>, and C<INI>.
59 This allows the parameters to be set at run time.
60  
61 =item * C<directory>
62  
63 The directory containing the file obituaries.sql.
64 If only one argument is given to C<new()>, it is taken to be C<directory>.
65  
66 =item * C<logger> - Passed to L<Database::Abstraction>
67  
68 =back
69  
70 =cut
71  
72 sub new
73 12 ▶{
Subroutine new: called CC=13 SCAR=26.7
Pod documented
74 12 my $class = shift;
75 12 my %args;
76  
77 # Handle hash or hashref arguments
78 12 ▶ if(ref($_[0]) eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 1 11 12
elsif (scalar(@_) % 2 == 0) { } 11 0 11
elsif (scalar @_ == 1) { } 0 0 0
79 1 %args = %{$_[0]};
80 } elsif((scalar(@_) % 2) == 0) {
81 11 %args = @_;
82 } elsif(scalar(@_) == 1) {
83 0 $args{'directory'} = shift;
84 }
85  
86 12 ▶ if(!defined($class)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $class) { } 1 11 12
elsif (builtin::blessed($class)) { } 2 9 11
87 1 ▶ if((scalar keys %args) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %args > 0) 0 1 1
88 # Use Genealogy::ObituaryDailyTimes->new, not Genealogy::ObituaryDailyTimes::new
89 0 carp(__PACKAGE__, ' use ->new() not ::new() to instantiate');
90 0 return;
91 }
92  
93 # FIXME: this only works when no arguments are given
94 1 $class = __PACKAGE__;
95 } elsif(Scalar::Util::blessed($class)) {
96 # If $class is an object, clone it with new arguments
97 2 return bless { %{$class}, %args }, ref($class);
98 }
99  
100 # Load the configuration from a config file, if provided
101 10 ▶ if(exists($args{'config_file'}) && (my $config = Config::Abstraction->new(config_dirs => ['/'], config_file => $args{'config_file'})->all())) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"config_file"} and my $config = "Config::Abstraction"->new("config_dirs", ["/"], "config_file", $args{"config_file"})->all) 1 9 10
Condition66%2/3
exists $args{"config_file"} and my $config = "Config::Abstraction"->new("config_dirs", ["/"], "config_file", $args{"config_file"})->all
!ll&&!rl&&r
901
MC/DC50%1/2
exists $args{"config_file"} and my $config = "Config::Abstraction"->new("config_dirs", ["/"], "config_file", $args{"config_file"})->all
exists $args{"config_file"} my $config = "Config::Abstraction"->new("config_dirs", ["/"], "config_file", $args{"config_file"})->all
Truth table66%2/3
A and B
A= exists $args{"config_file"}B= my $config = "Config::Abstraction"->new("config_dirs", ["/"], "config_file", $args{"config_file"})->all
ABresult
0X0
100
111
102 # my $config = YAML::XS::LoadFile($args{'config_file'});
103 1 ▶ if($config->{$class}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$config{$class}) 0 1 1
104 0 $config = $config->{$class};
105 }
106 1 %args = (%{$config}, %args);
107 }
108  
109 10 ▶ my $directory = $args{'directory'} || $Database::Abstraction{'defaults'}{'directory'};
Condition66%2/3
$args{'directory'} || $Database::Abstraction{'defaults'}{'directory'}
l!l&&r!l&&!r
604
MC/DC50%1/2
$args{'directory'} || $Database::Abstraction{'defaults'}{'directory'}
$args{'directory'} $Database::Abstraction{'defaults'}{'directory'}
Truth table66%2/3
A || B
A= $args{'directory'}B= $Database::Abstraction{'defaults'}{'directory'}
ABresult
1X1
011
000
110 10 ▶ if(!defined($directory)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $directory) 4 6 10
111 # If the directory argument isn't given, see if we can find the data
112 4 $directory = Module::Info->new_from_loaded(__PACKAGE__)->file();
113 4 $directory =~ s/\.pm$//;
114 4 $args{'directory'} = File::Spec->catfile($directory, 'data');
115 }
116  
117 10 ▶ if(!-d $directory) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $directory) 2 8 10
118 2 Carp::carp(__PACKAGE__, ": $directory is not a directory");
119 2 return;
120 }
121  
122 # cache_duration can be overridden by the args
123 8 return bless {
124 cache_duration => '1 day', # The database is updated daily
125 %args,
126 }, $class;
127 }
128  
129 =head2 search
130  
131 Searches the database.
132  
133 # Returns an array of hashrefs
134 my @smiths = $obits->search(last => 'Smith'); # You must at least define the last name to search for
135  
136 print $smiths[0]->{'first'}, "\n";
137  
138 Supports two return modes:
139  
140 =over 4
141  
142 =item * C<List context>
143  
144 Returns an array of hash references.
145  
146 =item * C<Scalar context>
147  
148 Returns a single hash reference,
149 or C<undef> if there is no match.
150  
151 =back
152  
153 =cut
154  
155 sub search
156 4 ▶{
Subroutine search: called CC=7 SCAR=24.9
Pod documented
157 4 my $self = shift;
158 4 my $params = Params::Get::get_params('last', @_);
159  
160 3 ▶ if(!defined($params->{'last'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$params{"last"}) 0 3 3
161 0 Carp::carp("Value for 'last' is mandatory");
162 0 return;
163 }
164  
165 3 ▶ $self->{'obituaries'} ||= Genealogy::ObituaryDailyTimes::obituaries->new(no_entry => 1, no_fixate => 1, %{$self});
Condition66%2/3
$$self{"obituaries"} ||= "Genealogy::ObituaryDailyTimes::obituaries"->new("no_entry", 1, "no_fixate", 1, %{$self;})
l!l&&r!l&&!r
120
MC/DC0%0/2
$$self{"obituaries"} ||= "Genealogy::ObituaryDailyTimes::obituaries"->new("no_entry", 1, "no_fixate", 1, %{$self;})
$$self{"obituaries"} "Genealogy::ObituaryDailyTimes::obituaries"->new("no_entry", 1, "no_fixate", 1, %{$self;})
Truth table66%2/3
A ||= B
A= $$self{"obituaries"}B= "Genealogy::ObituaryDailyTimes::obituaries"->new("no_entry", 1, "no_fixate", 1, %{$self;})
ABresult
1X1
011
000
166  
167 3 ▶ if(!defined($self->{'obituaries'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"obituaries"}) 0 3 3
168 0 Carp::croak("Can't open the obituaries database");
169 }
170  
171 3 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 3 0 3
172 3 my @obituaries = @{$self->{'obituaries'}->selectall_hashref($params)};
173 3 foreach my $obit(@obituaries) {
174 6 $obit->{'url'} = _create_url($obit);
175 }
176 3 return @obituaries;
177 }
178 0 ▶ if(defined(my $obit = $self->{'obituaries'}->fetchrow_hashref($params))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $obit = $$self{"obituaries"}->fetchrow_hashref($params))) 0 0 0
179 0 $obit->{'url'} = _create_url($obit);
180 0 Data::Reuse::fixate(%{$obit});
181 0 return $obit;
182 }
183 0 return; # undef
184 }
185  
186 10 ▶sub _create_url {
Subroutine _create_url: called CC=8 SCAR=23.0
187 10 my $obit = shift;
188 10 my $source = $obit->{'source'};
189 10 my $page = $obit->{'page'};
190  
191 10 ▶ if(!defined($page)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $page) 1 9 10
192 # use Data::Dumper;
193 # ::diag(Data::Dumper->new([$obit])->Dump());
194 1 Carp::croak(__PACKAGE__, ': undefined $page');
195 }
196 9 ▶ if(!defined($source)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source) 1 8 9
197 1 Carp::croak(__PACKAGE__, ": $page: undefined source");
198 }
199  
200 8 ▶ if($source eq 'M') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source eq "M") 4 4 8
201 4 return URLS->{'M'} . $page;
202 }
203 4 ▶ if($source eq 'F') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source eq "F") 3 1 4
204 3 return URLS->{'F'} . $page;
205 }
206 1 ▶ if($source eq 'L') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source eq "L") 0 1 1
207 0 ▶ if($obit->{'newspaper'} =~ /^https?:\/\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$obit{"newspaper"} =~ m[^https?://]) 0 0 0
208 0 return $obit->{'newspaper'};
209 }
210 0 ▶ if($obit->{'page'} =~ /^https?:\/\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$obit{"page"} =~ m[^https?://]) 0 0 0
211 0 return $obit->{'page'};
212 }
213 0 Carp::croak(__PACKAGE__, ": undefined newspaper. Newspaper much be given when source type is 'L'");
214 }
215 1 Carp::croak(__PACKAGE__, ": Invalid source, '$source'. Valid sources are 'M', 'F' and 'L'");
216 }
217  
218 =head1 AUTHOR
219  
220 Nigel Horne, C<< <njh at bandsman.co.uk> >>
221  
222 =head1 BUGS
223  
224 Ancestry has removed the archives.
225 The first 18 pages are on Wayback machine, but the rest is lost.
226  
227 =head1 SEE ALSO
228  
229 L<Database::Abstraction>
230  
231 =over 4
232  
233 =item * The Obituary Daily Times
234  
235 L<https://sites.rootsweb.com/~obituary/>
236  
237 =item * Archived Rootsweb data
238  
239 L<https://wayback.archive-it.org/20669/20231102044925/https://mlarchives.rootsweb.com/listindexes/emails?listname=gen-obit>
240  
241 =item * Funeral Notices
242  
243 L<https://www.funeral-notices.co.uk>
244  
245 =item * Recent data
246  
247 L<https://www.freelists.org/list/obitdailytimes>
248  
249 =item * Older data
250  
251 L<https://obituaries.rootsweb.com/obits/searchObits>
252  
253 =back
254  
255 =head1 SUPPORT
256  
257 You can find documentation for this module with the perldoc command.
258  
259 perldoc Genealogy::ObituaryDailyTimes
260  
261 You can also look for information at:
262  
263 =over 4
264  
265 =item * MetaCPAN
266  
267 L<https://metacpan.org/release/Genealogy-ObituaryDailyTimes>
268  
269 =item * RT: CPAN's request tracker
270  
271 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Genealogy-ObituaryDailyTimes>
272  
273 =item * CPAN Testers' Matrix
274  
275 L<http://matrix.cpantesters.org/?dist=Genealogy-ObituaryDailyTimes>
276  
277 =item * CPAN Testers Dependencies
278  
279 L<http://deps.cpantesters.org/?module=Genealogy::ObituaryDailyTimes>
280  
281 =back
282  
283 =head1 LICENSE AND COPYRIGHT
284  
285 Copyright 2020-2025 Nigel Horne.
286  
287 This program is released under the following licence: GPL2
288  
289 =cut
290  
291 5 1;
↑ Summary ObituaryDailyTimes/obituaries.pm »