blib/lib/Date/Lectionary/Daily.pm

filter: Statementstmt 94.3% 134 / 142 Branchbran 83.3% 15 / 18 Conditioncond 88.8% 8 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 82.8% 29 / 35 Podpod 100% 1 / 1 totaltotal 90.0% 189 / 210 CC 13 SCAR 9.7
CC
13
Cov
93%
BUILD
8.0
_buildTradition
3.3
_buildType
3.1
CRAP 2.6
↑ Summary
1 package Date::Lectionary::Daily;
2  
3 5 ▶use v5.22;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Try::Catch;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use File::Share ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Date::Lectionary::Time qw(isSunday prevSunday);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Date::Lectionary::Day;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 ▶use version; our $VERSION = version->declare("v1.20180423");
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =encoding utf8
22 =head1 NAME
23  
24 Date::Lectionary::Daily - Daily Readings for the Christian Lectionary
25  
26 =head1 VERSION
27  
28 Version 1.20180423
29  
30 =cut
31  
32 =head1 SYNOPSIS
33  
34 use Time::Piece;
35 use Date::Lectionary::Daily;
36  
37 #Using the old ACNA Liturgical Daily Lectionary
38 my $dailyReading = Date::Lectionary::Daily->new(
39 'date' => Time::Piece->strptime("2017-12-24", "%Y-%m-%d"),
40 'lectionary' => 'acna-xian'
41 );
42 say $dailyReading->readings->{evening}->{1}; #First lesson for evening prayer, Isaiah 51
43  
44 #Using the new ACNA Secular/Civil Daily Lectionary
45 my $dailyNewReading = Date::Lectionary::Daily->new(
46 'date' => Time::Piece->strptime( "2018-03-12", "%Y-%m-%d" ),
47 'lectionary' => 'acna-sec'
48 );
49 say $dailyNewReading->readings->{morning}->{2}; #Second lesson for morning prayer, Matthew 5
50  
51 =head1 DESCRIPTION
52  
53 Date::Lectionary::Daily takes a Time::Piece date and returns readings for morning and evening prayer for that date.
54  
55 =head2 CONSTRUCTOR ATTRIBUTES
56  
57 =head3 date
58  
59 The Time::Piece object date of the day you woudl like the lessons for.
60  
61 =head3 lectionary
62  
63 One of two choices `acna-sec` for the new secular calendar based ACNA daily lectionary or `acna-xian` for the previous liturgically-based ACNA daily lectionary.
64  
65 If lectionary is not given at construction, the ACNA secular daily lectionary — `acna-sec` — will be used.
66  
67 =head2 ATTRIBUTES
68  
69 =head3 week
70  
71 The name of the liturgical week in the lectionary; e.g. `The First Sunday in Lent`.
72  
73 =head3 day
74  
75 The name of the day of the week; e.g. `Sunday`.
76  
77 =head3 tradition
78  
79 Presently only returns `acna`. Future version of the module may include daily lectionary from other traditions.
80  
81 =head3 type
82  
83 Returns `secular` for daily lectionaries based on the secular/civil calendar and `liturgical` for daily lectionaries based on the liturgical calendar.
84  
85 =head3 readings
86  
87 A hasref of the readings for the day.
88  
89 =cut
90  
91 5 enum 'DailyLectionary', [qw(acna-sec acna-xian)];
92 5 enum 'Tradition', [qw(acna)];
93 5 enum 'LectionaryType', [qw(secular liturgical)];
94 5 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 =head1 SUBROUTINES/METHODS
97  
98 =cut
99  
100 5 has 'date' => (
101 is => 'ro',
102 isa => 'Time::Piece',
103 required => 1,
104 );
105  
106 5 has 'week' => (
107 is => 'ro',
108 isa => 'Str',
109 writer => '_setWeek',
110 init_arg => undef,
111 );
112  
113 5 has 'day' => (
114 is => 'ro',
115 isa => 'Str',
116 writer => '_setDay',
117 init_arg => undef,
118 );
119  
120 5 has 'lectionary' => (
121 is => 'ro',
122 isa => 'DailyLectionary',
123 default => 'acna-sec',
124 );
125  
126 5 has 'tradition' => (
127 is => 'ro',
128 isa => 'Tradition',
129 writer => '_setTradition',
130 init_arg => undef,
131 );
132  
133 5 has 'type' => (
134 is => 'ro',
135 isa => 'LectionaryType',
136 writer => '_setType',
137 init_arg => undef,
138 );
139  
140 5 has 'readings' => (
141 is => 'ro',
142 isa => 'HashRef',
143 writer => '_setReadings',
144 init_arg => undef,
145 );
146  
147 =head2 BUILD
148  
149 Constructor for the Date::Lectionary object. Takes a Time::Piect object, C<date>, to create the object.
150  
151 =cut
152  
153 sub BUILD {
154 92 ▶ my $self = shift;
Subroutine BUILD: called CC=8 SCAR=20.8
Pod documented
155  
156 92 $self->_setTradition( _buildTradition( $self->lectionary ) );
157 92 $self->_setType( _buildType( $self->lectionary ) );
158  
159 92 my $sunday;
160 92 ▶ if ( isSunday( $self->date ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (isSunday($self->date)) { } 14 78 92
161 14 $sunday = $self->date;
162 }
163 else {
164 78 $sunday = prevSunday( $self->date );
165 }
166  
167 92 my $fixedHolyDay = 0;
168 92 ▶ if ( $self->lectionary eq 'acna-xian' && ( $self->date->mon == 1 || $self->date->mon == 12 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lectionary eq "acna-xian" and $self->date->mon == 1 || $self->date->mon == 12) 13 79 92
Condition100%6/6
$self->lectionary eq "acna-xian" and $self->date->mon == 1 || $self->date->mon == 12
!ll&&!rl&&r
344810
$self->date->mon == 1 or $self->date->mon == 12
l!l&&r!l&&!r
4945
MC/DC66%2/3
$self->lectionary eq "acna-xian" and $self->date->mon == 1 || $self->date->mon == 12
$self->lectionary eq "acna-xian" $self->date->mon == 1 $self->date->mon == 12
Truth table75%3/4
A and B or C
A= $self->lectionary eq "acna-xian"B= $self->date->mon == 1C= $self->date->mon == 12
ABCresult
0XX0
1000
11X1
1011
169 13 $fixedHolyDay = _checkFixed( $self->date, $self->lectionary );
170 }
171  
172 $self->_setWeek(
173 92 Date::Lectionary::Day->new(
174 'date' => $sunday,
175 'lectionary' => $self->tradition,
176 'includeFeasts' => 'no',
177 )->name
178 );
179  
180 92 ▶ if ( $self->type eq 'liturgical' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->type eq 'liturgical') { } 58 34 92
elsif ($self->type eq 'secular') { } 34 0 34
181 58 ▶ if ($fixedHolyDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fixedHolyDay) { } 5 53 58
182 5 $self->_setReadings( _buildReadingsLiturgical( "Fixed Holy Days", $self->date->fullmonth . " " . $self->date->mday, $self->lectionary ) );
183 }
184 else {
185 53 $self->_setReadings( _buildReadingsLiturgical( $self->week, $self->date->fullday, $self->lectionary ) );
186 }
187 }
188 elsif ( $self->type eq 'secular' ) {
189 34 $self->_setReadings( _buildReadingsSecular( $self->week, $self->date, $self->lectionary ) );
190 }
191  
192 }
193  
194 =head2 _buildType
195  
196 Private method to determine if the daily lectionary follows the secular calendar or the liturgical calendar.
197  
198 =cut
199  
200 sub _buildType {
201 92 ▶ my $lectionary = shift;
Subroutine _buildType: called CC=3 SCAR=11.2
202  
203 92 ▶ if ( $lectionary eq 'acna-xian' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lectionary eq "acna-xian") 58 34 92
204 58 return 'liturgical';
205 }
206 34 ▶ if ( $lectionary eq 'acna-sec' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lectionary eq "acna-sec") 34 0 34
207 34 return 'secular';
208 }
209  
210 0 return undef;
211 }
212  
213 =head2 _buildTradition
214  
215 Private method to determine the Sunday lectionary tradition of the daily lectionary selected. Used to determine the liturgical week the day falls within.
216  
217 =cut
218  
219 sub _buildTradition {
220 92 ▶ my $lectionary = shift;
Subroutine _buildTradition: called CC=3 SCAR=12.0
221  
222 92 ▶ if ( $lectionary eq 'acna-xian' || $lectionary eq 'acna-sec' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lectionary eq "acna-xian" or $lectionary eq "acna-sec") 92 0 92
Condition66%2/3
$lectionary eq "acna-xian" or $lectionary eq "acna-sec"
l!l&&r!l&&!r
58340
MC/DC0%0/2
$lectionary eq "acna-xian" or $lectionary eq "acna-sec"
$lectionary eq "acna-xian" $lectionary eq "acna-sec"
Truth table66%2/3
A or B
A= $lectionary eq "acna-xian"B= $lectionary eq "acna-sec"
ABresult
1X1
011
000
223 92 return 'acna';
224 }
225  
226 0 return undef;
227 }
228  
229 =head2 _parseLectDB
230  
231 Private method to open and parse the lectionary XML to be used by other methods to XPATH queries.
232  
233 =cut
234  
235 sub _parseLectDB {
236 105 ▶ my $lectionary = shift;
Subroutine _parseLectDB: called CC=1 SCAR=0.0
237  
238 105 my $parser = XML::LibXML->new();
239 105 my $lectDB;
240  
241 try {
242 105 ▶ my $data_location = dist_file( 'Date-Lectionary-Daily', $lectionary . '_lect_daily.xml' );
Subroutine __ANON__: called CC=1 SCAR=0.0
243 105 $lectDB = $parser->parse_file($data_location);
244 }
245 catch {
246 0 ▶ carp "The readings database for the $lectionary daily lectionary could not be found or parsed.";
Subroutine __ANON__: not called CC=1 SCAR=6.9
247 105 };
248  
249 105 return $lectDB;
250 }
251  
252 =head2 _checkFixed
253  
254 Private method to determine if the day given is a fixed holiday rather than a standard day.
255  
256 =cut
257  
258 sub _checkFixed {
259 13 ▶ my $date = shift;
Subroutine _checkFixed: called CC=2 SCAR=6.9
260 13 my $lectionary = shift;
261  
262 13 my $searchDate = $date->fullmonth . " " . $date->mday;
263  
264 13 my $lectDB = _parseLectDB($lectionary);
265  
266 13 my $fixed_xpath;
267  
268 try {
269 13 ▶ $fixed_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/week[\@name=\"Fixed Holy Days\"]/day[\@name=\"$searchDate\"]/lesson");
Subroutine __ANON__: called CC=1 SCAR=0.0
270 }
271 catch {
272 0 ▶ carp "Could not compile the XPath Expression for $searchDate in the $lectionary lectionary.";
Subroutine __ANON__: not called CC=1 SCAR=6.9
273 13 };
274  
275 13 ▶ if ( $lectDB->exists($fixed_xpath) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lectDB->exists($fixed_xpath)) 5 8 13
276 5 return 1;
277 }
278  
279 8 return 0;
280 }
281  
282 =head2 _buildReadingsLiturgical
283  
284 Private method that returns an ArrayRef of strings for the lectionary readings associated with the date according to the liturgical calendar.
285  
286 =cut
287  
288 sub _buildReadingsLiturgical {
289 58 ▶ my $weekName = shift;
Subroutine _buildReadingsLiturgical: called CC=1 SCAR=0.0
290 58 my $weekDay = shift;
291 58 my $lectionary = shift;
292  
293 58 my $readings = _parseLectDB($lectionary);
294  
295 58 my $morn1_xpath;
296 my $morn2_xpath;
297 58 my $eve1_xpath;
298 58 my $eve2_xpath;
299 try {
300 58 ▶ $morn1_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/week[\@name=\"$weekName\"]/day[\@name=\"$weekDay\"]/lesson[\@service=\"morning\" and \@order=\"1\"]");
Subroutine __ANON__: called CC=1 SCAR=0.0
301 58 $morn2_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/week[\@name=\"$weekName\"]/day[\@name=\"$weekDay\"]/lesson[\@service=\"morning\" and \@order=\"2\"]");
302 58 $eve1_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/week[\@name=\"$weekName\"]/day[\@name=\"$weekDay\"]/lesson[\@service=\"evening\" and \@order=\"1\"]");
303 58 $eve2_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/week[\@name=\"$weekName\"]/day[\@name=\"$weekDay\"]/lesson[\@service=\"evening\" and \@order=\"2\"]");
304 }
305 catch {
306 0 ▶ carp "Could not compile the XPath Expression for $weekDay in $weekName in the $lectionary lectionary.";
Subroutine __ANON__: not called CC=1 SCAR=6.9
307 58 };
308  
309 58 my %readings;
310 try {
311 58 ▶ %readings = (
Subroutine __ANON__: called CC=1 SCAR=0.0
312 morning => {
313 1 => $readings->find($morn1_xpath)->string_value(),
314 2 => $readings->find($morn2_xpath)->string_value()
315 },
316 evening => {
317 1 => $readings->find($eve1_xpath)->string_value(),
318 2 => $readings->find($eve2_xpath)->string_value()
319 }
320 );
321 }
322 catch {
323 0 ▶ carp "The readings for $weekDay in $weekName in the $lectionary lectionary could not be found.";
Subroutine __ANON__: not called CC=1 SCAR=6.9
324 58 };
325  
326 58 return \%readings;
327 }
328  
329 =head2 _buildReadingsSecular
330  
331 Private method that returns an ArrayRef of strings for the lectionary readings associated with the date according to the secular calendar.
332  
333 =cut
334  
335 sub _buildReadingsSecular {
336 34 ▶ my $weekName = shift;
Subroutine _buildReadingsSecular: called CC=1 SCAR=0.0
337 34 my $date = shift;
338 34 my $lectionary = shift;
339  
340 34 my $readings = _parseLectDB($lectionary);
341  
342 34 my $seekDate = substr( $date->ymd, 5, 5 );
343  
344 34 my $morn1_xpath;
345 my $morn2_xpath;
346 34 my $eve1_xpath;
347 34 my $eve2_xpath;
348 try {
349 34 ▶ $morn1_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/day[\@date=\"$seekDate\"]/lesson[\@service=\"morning\" and \@order=\"1\"]");
Subroutine __ANON__: called CC=1 SCAR=0.0
350 34 $morn2_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/day[\@date=\"$seekDate\"]/lesson[\@service=\"morning\" and \@order=\"2\"]");
351 34 $eve1_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/day[\@date=\"$seekDate\"]/lesson[\@service=\"evening\" and \@order=\"1\"]");
352 34 $eve2_xpath = XML::LibXML::XPathExpression->new("/daily-lectionary/day[\@date=\"$seekDate\"]/lesson[\@service=\"evening\" and \@order=\"2\"]");
353 }
354 catch {
355 0 ▶ carp "Could not compile the XPath Expression for $seekDate in $weekName in the $lectionary lectionary.";
Subroutine __ANON__: not called CC=1 SCAR=6.9
356 34 };
357  
358 34 my %readings;
359 try {
360 34 ▶ %readings = (
Subroutine __ANON__: called CC=1 SCAR=0.0
361 morning => {
362 1 => $readings->find($morn1_xpath)->string_value(),
363 2 => $readings->find($morn2_xpath)->string_value()
364 },
365 evening => {
366 1 => $readings->find($eve1_xpath)->string_value(),
367 2 => $readings->find($eve2_xpath)->string_value()
368 }
369 );
370 }
371 catch {
372 0 ▶ carp "The readings for $seekDate in $weekName in the $lectionary lectionary could not be found.";
Subroutine __ANON__: not called CC=1 SCAR=6.9
373 34 };
374  
375 34 return \%readings;
376 }
377  
378 =head1 AUTHOR
379  
380 Michael Wayne Arnold, C<< <michael at rnold.info> >>
381  
382 =head1 BUGS
383  
384 =for html <a href="https://travis-ci.org/marmanold/Date-Lectionary-Daily"><img src="https://travis-ci.org/marmanold/Date-Lectionary-Daily.svg?branch=master"></a>
385  
386 =for html <a href='https://coveralls.io/github/marmanold/Date-Lectionary-Daily?branch=master'><img src='https://coveralls.io/repos/github/marmanold/Date-Lectionary-Daily/badge.svg?branch=master' alt='Coverage Status' /></a>
387  
388 Please report any bugs or feature requests to C<bug-date-lectionary-daily at rt.cpan.org>, or through
389 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Date-Lectionary-Daily>. I will be notified, and then you'll
390 automatically be notified of progress on your bug as I make changes.
391  
392 =head1 SUPPORT
393  
394 You can find documentation for this module with the perldoc command.
395  
396 perldoc Date::Lectionary::Daily
397  
398  
399 You can also look for information at:
400  
401 =over 4
402  
403 =item * RT: CPAN's request tracker (report bugs here)
404  
405 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Date-Lectionary-Daily>
406  
407 =item * AnnoCPAN: Annotated CPAN documentation
408  
409 L<http://annocpan.org/dist/Date-Lectionary-Daily>
410  
411 =item * CPAN Ratings
412  
413 L<http://cpanratings.perl.org/d/Date-Lectionary-Daily>
414  
415 =item * Search CPAN
416  
417 L<http://search.cpan.org/dist/Date-Lectionary-Daily/>
418  
419 =back
420  
421  
422 =head1 ACKNOWLEDGEMENTS
423  
424 Many thanks to my beautiful wife, Jennifer, my amazing daughter, Rosemary, and my sweet son, Oliver. But, above all, SOLI DEO GLORIA!
425  
426 =head1 LICENSE
427  
428 Copyright 2017-2018 MICHAEL WAYNE ARNOLD
429  
430 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
431  
432 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
433  
434 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
435  
436 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
437  
438  
439 =cut
440  
441 5 __PACKAGE__->meta->make_immutable;
442  
443 5 1; # End of Date::Lectionary::Daily
↑ Summary