Natural/Calendar.pm

filter: Statementstmt 100% 35 / 35 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 97.9% 48 / 49 CC 3 SCAR 4.1
CC
3
Cov
97%
_type
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Natural/Helpers.pm ↑ Summary
1 package DateTime::Format::Natural::Calendar;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 27 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 27 our $VERSION = '0.02';
9  
10 sub _init
11 72 ▶{
Subroutine _init: called CC=1 SCAR=0.0
12 72 my ($class) = @_;
13  
14 72 my $type = _type($class);
15  
16 72 return "DateTime::Format::Natural::Calendar::${type}"->_new(calendar_class => $class, type => $type);
17 }
18  
19 sub _type
20 72 ▶{
Subroutine _type: called CC=3 SCAR=11.0
21 72 my ($class) = @_;
22  
23 72 ▶ if (defined $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $class) { } 36 36 72
24 36 ▶ return 'julian' if $class eq 'DateTime::Calendar::Julian';
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "DateTime::Calendar::Julian" 36 0 36
25 }
26 else {
27 36 return 'gregorian';
28 }
29 }
30  
31 sub _can_convert
32 72 ▶{
Subroutine _can_convert: called CC=1 SCAR=0.0
33 72 my $self = shift;
34  
35 72 return $self->can('_to_gregorian');
36 }
37  
38 sub _new
39 72 ▶{
Subroutine _new: called CC=1 SCAR=0.0
40 72 my $class = shift;
41  
42 72 return bless { @_ }, $class;
43 }
44  
45 27 1;
46  
47 package DateTime::Format::Natural::Calendar::gregorian;
48  
49 27 ▶use base 'DateTime::Format::Natural::Calendar';
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 27 1;
52  
53 package DateTime::Format::Natural::Calendar::julian;
54  
55 27 ▶use base 'DateTime::Format::Natural::Calendar';
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 sub _to_gregorian
58 36 ▶{
Subroutine _to_gregorian: called CC=1 SCAR=0.0
59 36 my $self = shift;
60 36 my ($year, $month, $day, $opts, $code) = @_;
61  
62 36 $code->(\$year, \$month, \$day, $opts);
63  
64 36 my $dt = DateTime->from_object(object => $self->{calendar_class}->new(year => $year, month => $month, day => $day));
65  
66 36 return map $dt->$_, qw(year month day);
67 }
68  
69 27 1;
70 __END__
« Natural/Helpers.pm ↑ Summary