blib/lib/Date/Advent.pm

filter: Statementstmt 100% 59 / 59 Branchbran 100% 4 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 100% 80 / 80 CC 4 SCAR 6.2
CC
4
Cov
100%
BUILD
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
↑ Summary
1 package Date::Advent;
2  
3 2 ▶use v5.22;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Date::Lectionary::Time qw(nextSunday prevSunday);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 Date::Advent - Calculate the Sundays of Advent
18  
19 =head1 VERSION
20  
21 Version 1.20180423
22  
23 =cut
24  
25 2 ▶use version; our $VERSION = version->declare("v1.20180423");
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 =head1 SYNOPSIS
28  
29 Date::Advent takes a Time::Piece date and calculates all four Sundays of Advent for the current Christian liturgical year.
30  
31 As Advent is the beginning of the Christian liturgical calendar, this usually results in the date for Advent in the current year being dates in the past. E.g. The Sundays of Advent returned for 12. March 2016 would be 29. November 2015, 6. December 2015, 13. December 2015, and 20. December 2015.
32  
33 use Time::Piece;
34 use Date::Advent;
35  
36 my $testAdvent = Date::Advent->new(date => Time::Piece->strptime("2016-01-01", "%Y-%m-%d"));
37 say $testAdvent->firstSunday; #Gives date for first Sunday of Advent
38 say $testAdvent->secondSunday; #Gives date for second Sunday of Advent
39 say $testAdvent->thirdSunday; #Gives date for third Sunday of Advent
40 say $testAdvent->fourthSunday; #Gives date for fourth Sunday of Advent
41 say $testAdvent->christmas; #Gives date of Christmas
42  
43 =head1 Object Attributes
44  
45 =head2 date
46  
47 Time::Piece date object. Only attribute required at object construction.
48  
49 =head2 christmas
50  
51 Time::Piece attribute for Christmas Day as calculated from the C<date> given at object construction.
52  
53 =head2 firstSunday
54  
55 Time::Piece attribute for the first Sunday of Advent as calculated from the C<date> given at object construction.
56  
57 =head2 secondSunday
58  
59 Time::Piece attribute for the second Sunday of Advent as calculated from the C<date> given at object construction.
60  
61 =head2 thirdSunday
62  
63 Time::Piece attribute for the third Sunday of Advent as calculated from the C<date> given at object construction.
64  
65 =head2 fourthSunday
66  
67 Time::Piece attribute for the fourth Sunday of Advent as calculated from the C<date> given at object construction.
68  
69 =cut
70  
71 2 has 'date' => (
72 is => 'ro',
73 isa => 'Time::Piece',
74 );
75  
76 2 has 'christmas' => (
77 is => 'ro',
78 isa => 'Time::Piece',
79 init_arg => undef,
80 writer => '_setChristmas',
81 );
82  
83 2 has 'firstSunday' => (
84 is => 'ro',
85 isa => 'Time::Piece',
86 init_arg => undef,
87 writer => '_setFirstSunday',
88 );
89  
90 2 has 'secondSunday' => (
91 is => 'ro',
92 isa => 'Time::Piece',
93 init_arg => undef,
94 writer => '_setSecondSunday',
95 );
96  
97 2 has 'thirdSunday' => (
98 is => 'ro',
99 isa => 'Time::Piece',
100 init_arg => undef,
101 writer => '_setThirdSunday',
102 );
103  
104 2 has 'fourthSunday' => (
105 is => 'ro',
106 isa => 'Time::Piece',
107 init_arg => undef,
108 writer => '_setFourthSunday',
109 );
110  
111 =head1 Object Constructor
112  
113 =head2 BUILD
114  
115 Constructor for the Date::Advent object. Takes the Time::Piece argument of C<date> as the date to calculate the current Christian liturgical year's Sundays of Advent from. The resulting object is immutable and cannot be changed once created.
116  
117 my $testAdvent = Date::Advent->new(date => Time::Piece->strptime("2016-01-01", "%Y-%m-%d"));
118  
119 =cut
120  
121 4 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod documented
122 4 my $self = shift;
123  
124 4 my $xmasYear;
125 4 ▶ if ( $self->date->mon == 11 || $self->date->mon == 12 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->date->mon == 11 or $self->date->mon == 12) { } 3 1 4
Condition100%3/3
$self->date->mon == 11 or $self->date->mon == 12
l!l&&r!l&&!r
211
MC/DC100%2/2
$self->date->mon == 11 or $self->date->mon == 12
$self->date->mon == 11 $self->date->mon == 12
Truth table100%3/3
A or B
A= $self->date->mon == 11B= $self->date->mon == 12
ABresult
1X1
011
000
126 3 $xmasYear = $self->date->year;
127 }
128 else {
129 1 $xmasYear = $self->date->year - 1;
130 }
131  
132 4 my $christmasDay = Time::Piece->strptime( "$xmasYear-12-25", "%Y-%m-%d" );
133  
134 4 my $fourthAdvent = prevSunday($christmasDay);
135 4 my $thirdAdvent = prevSunday($fourthAdvent);
136 4 my $secondAdvent = prevSunday($thirdAdvent);
137 4 my $firstAdvent = prevSunday($secondAdvent);
138  
139 4 ▶ if ( $self->date < $firstAdvent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->date < $firstAdvent) 2 2 4
140 2 $christmasDay = $christmasDay->add_years(-1);
141  
142 2 $fourthAdvent = prevSunday($christmasDay);
143 2 $thirdAdvent = prevSunday($fourthAdvent);
144 2 $secondAdvent = prevSunday($thirdAdvent);
145 2 $firstAdvent = prevSunday($secondAdvent);
146 }
147  
148 4 $self->_setChristmas($christmasDay);
149 4 $self->_setFirstSunday($firstAdvent);
150 4 $self->_setSecondSunday($secondAdvent);
151 4 $self->_setThirdSunday($thirdAdvent);
152 4 $self->_setFourthSunday($fourthAdvent);
153 }
154  
155 =head1 AUTHOR
156  
157 Michael Wayne Arnold, C<< <michael at rnold.info> >>
158  
159 =head1 BUGS
160  
161 =for html <a href='https://travis-ci.org/marmanold/Date-Advent'><img src='https://travis-ci.org/marmanold/Date-Advent.svg?branch=master' /></a>
162  
163 =for html <a href='https://coveralls.io/github/marmanold/Date-Advent?branch=master'><img src='https://coveralls.io/repos/github/marmanold/Date-Advent/badge.svg?branch=master' alt='Coverage Status' /></a>
164  
165 Please report any bugs or feature requests to C<bug-date-advent at rt.cpan.org>, or through
166 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Date-Advent>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
167  
168 =head1 SUPPORT
169  
170 You can find documentation for this module with the perldoc command.
171  
172 perldoc Date::Advent
173  
174  
175 You can also look for information at:
176  
177 =over 4
178  
179 =item * RT: CPAN's request tracker (report bugs here)
180  
181 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Date-Advent>
182  
183 =item * AnnoCPAN: Annotated CPAN documentation
184  
185 L<http://annocpan.org/dist/Date-Advent>
186  
187 =item * CPAN Ratings
188  
189 L<http://cpanratings.perl.org/d/Date-Advent>
190  
191 =item * Search CPAN
192  
193 L<http://search.cpan.org/dist/Date-Advent/>
194  
195 =back
196  
197  
198 =head1 ACKNOWLEDGEMENTS
199  
200 Many thanks to my beautiful wife, Jennifer, my amazing daughter, Rosemary, and my sweet son, Oliver. But, above all, SOLI DEO GLORIA!
201  
202 =head1 LICENSE
203  
204 Copyright 2016-2018 MICHAEL WAYNE ARNOLD
205  
206 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
207  
208 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
209  
210 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.
211  
212 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.
213  
214  
215 =cut
216  
217 2 __PACKAGE__->meta->make_immutable;
218  
219 2 1; # End of Date::Advent
↑ Summary