blib/lib/MooseX/Types/DateTime/ButMaintained.pm

filter: Statementstmt 95.7% 68 / 71 Branchbran 75.0% 3 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.4% 19 / 21 Podpod n/a totaltotal 89.1% 90 / 101 CC 2 SCAR 1.7
CC
2
Cov
91%
__ANON__
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.2
↑ Summary
1 package MooseX::Types::DateTime::ButMaintained;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $VERSION = "0.16";
6  
7 3 ▶use Moose 0.41 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use DateTime::Locale ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use DateTime::TimeZone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Olson::Abbreviations 0.03 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use MooseX::Types::Moose 0.30 qw/Num HashRef Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use MooseX::Types 0.30 -declare => [qw( DateTime Duration TimeZone Locale Now )];
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 class_type "DateTime";
20 3 class_type "DateTime::Duration";
21 3 class_type "DateTime::TimeZone";
22 3 class_type "DateTime::Locale::root" => { name => "DateTime::Locale" };
23  
24 3 subtype DateTime, as 'DateTime';
25 3 subtype Duration, as 'DateTime::Duration';
26 3 subtype TimeZone, as 'DateTime::TimeZone';
27 3 subtype Locale, as 'DateTime::Locale';
28  
29 0 ▶subtype( Now, as Str, where { $_ eq 'now' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 ( $Moose::VERSION >= 2.0100
31 3 ▶ ? Moose::Util::TypeConstraints::inline_as {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 3 'no warnings "uninitialized";'.
33 '!ref(' . $_[1] . ') and '. $_[1] .' eq "now"';
34 }
35 3 ▶ : Moose::Util::TypeConstraints::optimize_as {
Branch: 1 branch
BranchTrueFalseTotal
$Moose::VERSION >= 2.01 ? : 3 0 3
36 3 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 0 ▶ !ref($_[0]) and $_[0] eq 'now';
Condition0%0/3
!ref($_[0]) && $_[0] eq 'now'
!ll&&!rl&&r
000
MC/DC0%0/2
!ref($_[0]) && $_[0] eq 'now'
!ref($_[0]) $_[0] eq 'now'
Truth table0%0/3
not(A) && B
A= !ref($_[0])B= $_[0] eq 'now'
ABresult
0X0
100
111
38 }
39 )
40 );
41  
42 our %coercions = (
43 DateTime => [
44 1 ▶ from Num, via { 'DateTime'->from_epoch( epoch => $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
45 1 ▶ , from HashRef, via { 'DateTime'->new( %$_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
46 1 ▶ , from Now, via { 'DateTime'->now }
Subroutine __ANON__: called CC=1 SCAR=0.0
47 ]
48  
49 , "DateTime::Duration" => [
50 1 ▶ from Num, via { DateTime::Duration->new( seconds => $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
51 1 ▶ , from HashRef, via { DateTime::Duration->new( %$_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
52 ]
53  
54 , "DateTime::TimeZone" => [
55 8 ▶ from Str, via {
Subroutine __ANON__: called CC=2 SCAR=6.9
56 # No abbreviation - assumed if we don't have a '/'
57 8 ▶ if ( m,/|floating|local, ) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[/|floating|local]) { } 4 4 8
58 4 return DateTime::TimeZone->new( name => $_ );
59 }
60 # Abbreviation - assumed if we do have a '/'
61 # returns a DateTime::TimeZone::OffsetOnly
62 else {
63 4 my $offset = Olson::Abbreviations->new({ tz_abbreviation => $_ })->get_offset;
64 2 return DateTime::TimeZone->new( name => $offset );
65 }
66 }
67 ]
68  
69 , "DateTime::Locale" => [
70 from Moose::Util::TypeConstraints::find_or_create_isa_type_constraint("Locale::Maketext")
71 0 ▶ , via { DateTime::Locale->load($_->language_tag) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 1 ▶ , from Str, via { DateTime::Locale->load($_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
73 3 ]
74 );
75  
76 3 for my $type ( "DateTime", DateTime ) {
77 6 coerce $type => @{ $coercions{DateTime} };
78 }
79  
80 3 for my $type ( "DateTime::Duration", Duration ) {
81 6 coerce $type => @{ $coercions{"DateTime::Duration"} };
82 }
83  
84 3 for my $type ( "DateTime::TimeZone", TimeZone ) {
85 6 coerce $type => @{ $coercions{"DateTime::TimeZone"} };
86 }
87  
88 3 for my $type ( "DateTime::Locale", Locale ) {
89 6 coerce $type => @{ $coercions{"DateTime::Locale"} };
90 }
91  
92 3 1;
93  
94 __END__
↑ Summary