| 1 | package Calendar::Any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | $Calendar::Any::VERSION = '0.5'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 0 | ▶ | '<=>' => sub { $_[0]->absolute_date <=> (ref $_[1] ? $_[1]->absolute_date : $_[1]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | '+' => \&add, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | '-' => \&substract, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | '""' => \&date_string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | '0+' => \&absolute_date; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | my $_class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | my $class = ref $_class || $_class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_class || $_class
MC/DC0%0/2
ref $_class || $_class
ref $_class
$_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | $self->{absolute} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | ▶ | sub new_from_Astro { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_Astro: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 8 | my ($self, $days) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | return $self->new($days - 1721424.5); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 11 | ▶ | sub absolute_date { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
absolute_date: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | return shift->{absolute}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 27 | ▶ | sub astro_date { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
astro_date: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 27 | return shift->absolute_date + 1721424.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub today { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
today: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my @time = localtime; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $date = $self->new_from_Gregorian($time[4]+1, $time[3], $time[5]+1900); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | return $self->new($date->absolute_date); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #{{{ Format functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | our @weekday_name = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | our @month_name = qw(January February March April May June July August September October November December); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | our $default_format = "%A"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 68 | ▶ | sub year { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
year: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 68 | return shift->{year}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 35 | ▶ | sub month { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
month: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 35 | return shift->{month}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 31 | ▶ | sub day { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
day: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 31 | return shift->{day}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub weekday { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
weekday: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return shift->{absolute} % 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub weekday_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
weekday_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return $weekday_name[shift->weekday]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub month_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
month_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return $month_name[shift->month-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | sub date_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date_string: called CC=5 SCAR=19.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | ▶ | no strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | my $fmt = shift || ${(ref $self||$self)."::default_format"} || $default_format; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
shift() || ${(ref $self || $self) . '::default_format';} || $default_format
shift() or ${(ref $self || $self) . '::default_format';}
ref $self || $self
MC/DC0%0/3
shift() || ${(ref $self || $self) . '::default_format';} || $default_format
shift()
${(ref $self || $self) . '::default_format';}
$default_format
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table25%1/4
A or B || C
A= shift()B= ${(ref $self || $self) . '::default_format';}C= $default_format
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | $fmt =~ s/ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | %(O?[%a-zA-Z]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | / | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | ($self->can("format_$1") || sub { $1 })->($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$self->can("format_$1") || sub {
$1;
}
MC/DC0%0/2
$self->can("format_$1") || sub {
$1;
}
$self->can("format_$1")
sub {
$1;
}
Truth table33%1/3
A || B
A= $self->can("format_$1")B= sub {
$1;
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | /sgeox; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 5 | return $fmt; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub format_d { sprintf("%02d", shift->day) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_d: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub format_m { sprintf("%02d", shift->month) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_m: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub format_A { shift->absolute_date } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_A: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub format_w { shift->weekday } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_w: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub format_W { shift->weekday_name } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_W: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub format_M { shift->month_name } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_M: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub format_Y { shift->year } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_Y: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | sub format_D { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_D: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | return join("/", map { sprintf "%02d", $_ } $self->month, $self->day, $self->year); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub format_F { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_F: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | return join("-", map { sprintf "%02d", $_ } $self->year, $self->month, $self->day); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | #{{{ Overload Operators | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub substract { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
substract: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my ($self, $operand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( ref $operand ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return $self->absolute_date - $operand->absolute_date; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return $self->new($self->absolute_date-$operand); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $operand) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | confess "operand must be numeric!\n" if ref $operand; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $self->new($self->absolute_date + $operand); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | #}}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 59 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 59 | our ($AUTOLOAD); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 59 | (my $subname = $AUTOLOAD) =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 59 | ▶ | if ( $AUTOLOAD =~ /::new_from_(\w+)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | my $module = "Calendar::Any::" . $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | eval("require $module"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | die "Can't load module $module: $@!\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | my $sub = *{$subname} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | return $module->new(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | goto &$sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } elsif ( $AUTOLOAD =~ /::to_(\w+)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | my $module = "Calendar::Any::" . $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 3 | eval("require $module"); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | die "Can't load module $module: $@!\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | my $sub = *{$subname} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | $_[0] = $module->new($_[0]->absolute_date); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | goto &$sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } elsif ( $AUTOLOAD =~ /DESTROY/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | die "Unknown function $AUTOLOAD\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||