| 1 | package Mindcal; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Log::Log4perl qw(:easy); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | ########################################### | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | ########################################### | ||||||||||||||||||||||||||||
| 12 | 1 | my($class, %options) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | my $self = { | |||||||||||||||||||||||||||
| 15 | month_items => [qw(0 3 3 6 1 4 6 2 5 0 3 5)], | ||||||||||||||||||||||||||||
| 16 | century_adjust => { | ||||||||||||||||||||||||||||
| 17 | qw(1700 4 1800 2 1900 0 2000 6 | ||||||||||||||||||||||||||||
| 18 | 2100 4 2200 2 2300 0) | ||||||||||||||||||||||||||||
| 19 | }, | ||||||||||||||||||||||||||||
| 20 | dows => [qw[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]], | ||||||||||||||||||||||||||||
| 21 | %options, | ||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | if(!defined $self->{date} or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $self->{"date"} or ref $self->{"date"} ne "DateTime"
MC/DC0%0/2
not defined $self->{"date"} or ref $self->{"date"} ne "DateTime"
not defined $self->{"date"}
ref $self->{"date"} ne "DateTime"
Truth table33%1/3
not(A) or B
A= not defined $self->{"date"}B= ref $self->{"date"} ne "DateTime"
| |||||||||||||||||||||||||||||
| 25 | ref($self->{date}) ne "DateTime") { | ||||||||||||||||||||||||||||
| 26 | 0 | LOGDIE "new() called without DateTime date"; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 30 | 1 | return $self; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ########################################### | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | sub month_item { | ||||||||||||||||||||||||||
|
Subroutine
month_item: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | ########################################### | ||||||||||||||||||||||||||||
| 36 | 2 | my($self) = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | return $self->{month_items}->[$self->{date}->month() - 1]; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | ########################################### | ||||||||||||||||||||||||||||
| 42 | 2 | ▶ | sub year_item { | ||||||||||||||||||||||||||
|
Subroutine
year_item: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | ########################################### | ||||||||||||||||||||||||||||
| 44 | 2 | my($self) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 2 | my $year = $self->{date}->year(); | |||||||||||||||||||||||||||
| 48 | 2 | my $year2 = ($year % 100); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | return (($year2 + ($year2 / 4)) % 7); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | ########################################### | ||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub century_adjust { | ||||||||||||||||||||||||||
|
Subroutine
century_adjust: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | ########################################### | ||||||||||||||||||||||||||||
| 56 | 2 | my($self) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | my $year = $self->{date}->year(); | |||||||||||||||||||||||||||
| 61 | 2 | my $month = $self->{date}->month(); | |||||||||||||||||||||||||||
| 62 | 2 | my $cent = $year / 100; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | if(!exists $self->{century_adjust}->{ $cent * 100 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | LOGDIE "Century $cent not supported (yet)."; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | return $self->{century_adjust}->{ $cent*100 }; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | ########################################### | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | sub day_item { | ||||||||||||||||||||||||||
|
Subroutine
day_item: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | ########################################### | ||||||||||||||||||||||||||||
| 74 | 2 | my($self) = @_; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | return $self->{date}->day(); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | ########################################### | ||||||||||||||||||||||||||||
| 80 | 1 | ▶ | sub weekday { | ||||||||||||||||||||||||||
|
Subroutine
weekday: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | ########################################### | ||||||||||||||||||||||||||||
| 82 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | my $dow = $self->year_item() + | |||||||||||||||||||||||||||
| 85 | $self->month_item() + | ||||||||||||||||||||||||||||
| 86 | $self->day_item() + | ||||||||||||||||||||||||||||
| 87 | $self->adjust; | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | return $self->{dows}->[ $dow % 7 ]; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | ########################################### | ||||||||||||||||||||||||||||
| 93 | 2 | ▶ | sub adjust { | ||||||||||||||||||||||||||
|
Subroutine
adjust: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | ########################################### | ||||||||||||||||||||||||||||
| 95 | 2 | my($self) = @_; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | my $adj = $self->century_adjust(); | |||||||||||||||||||||||||||
| 98 | 2 | my $month = $self->{date}->month(); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | $adj-- if $self->is_leap_year() and $month <= 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->is_leap_year and $month <= 2
MC/DC0%0/2
$self->is_leap_year and $month <= 2
$self->is_leap_year
$month <= 2
Truth table33%1/3
A and B
A= $self->is_leap_yearB= $month <= 2
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2 | return $adj; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | ########################################### | ||||||||||||||||||||||||||||
| 106 | 2 | ▶ | sub is_leap_year { | ||||||||||||||||||||||||||
|
Subroutine
is_leap_year: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | ########################################### | ||||||||||||||||||||||||||||
| 108 | 2 | my($self) = @_; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | my $year = $self->{date}->year(); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | ▶ | return 0 if $year % 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 2 | ▶ | return 1 if $year % 100; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 2 | ▶ | return 0 if $year % 400; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 2 | return 1; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||