Pad/Type/Temporal.pm

filter: Statementstmt 100% 63 / 63 Branchbran 87.5% 7 / 8 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 12 / 12 Podpod 71.4% 5 / 7 totaltotal 92.8% 91 / 98 CC 7 SCAR 10.4
CC
7
Cov
96%
checkSpecKeys
6.1
zoneNamed
2.0
BEGIN
1.0
CRAP 2.8
« Pad/Spec.pm ↑ Summary Pad/Result.pm »
1 23 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 23 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 23 ▶use Getopt::Pad::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 class Getopt::Pad::Type::Temporal :isa(Getopt::Pad::Type) :abstract {
7 23 ▶ use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 our $VERSION = '0.06';
10  
11 23 ▶ use constant SPEC_KEYS => ['timezone'];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 field $timezone :param :reader = 'local';
14 1 ▶ field $zone :reader;
Subroutine timezone: called CC=1 SCAR=0.0
Subroutine zone: called CC=1 SCAR=0.0
Pod documented
Pod documented
15  
16 # DateTime::Format::Natural is optional: a missing module, like an
17 # unknown time zone, is a spec mistake reported when the spec is built.
18 4 ▶ method checkSpecKeys :common (%args) {
Subroutine checkSpecKeys: called CC=6 SCAR=18.1
Pod documented
19 4 ▶ return sprintf("type '%s' requires the DateTime::Format::Natural module", $class->NAMES->[0]) if !$class->isNaturalInstalled;
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isNaturalInstalled 2 2 4
20  
21 2 ▶ my $name = $args{timezone} // 'local';
Condition100%2/2
$args{"timezone"} // "local"
l!l
11
MC/DC100%1/1
$args{"timezone"} // "local"
$args{"timezone"}
Truth table100%2/2
A
A= $args{"timezone"}
Aresult
11
00
22 2 ▶ return 'timezone must be a non-empty string' if ref $name || $name eq '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $name or $name eq "" 0 2 2
Condition33%1/3
ref $name or $name eq ""
l!l&&r!l&&!r
002
MC/DC0%0/2
ref $name or $name eq ""
ref $name $name eq ""
Truth table33%1/3
A or B
A= ref $nameB= $name eq ""
ABresult
1X1
011
000
23 2 ▶ return sprintf("timezone '%s' is not a known time zone", $name) if !defined $class->zoneNamed($name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class->zoneNamed($name) 1 1 2
24 1 return undef;
25 23 }
26  
27 6 ▶ method isNaturalInstalled :common () {
Subroutine isNaturalInstalled: called CC=1 SCAR=0.0
Pod undocumented
28 6 try {
29 6 require DateTime::Format::Natural;
30 4 require DateTime::TimeZone;
31 4 return 1;
32 }
33 catch ($error) {
34 2 return 0;
35 }
36 23 }
37  
38 # The DateTime::TimeZone called $name, or undef for an unknown name. A
39 # local zone the system cannot tell is floating rather than an error.
40 7 ▶ method zoneNamed :common ($name) {
Subroutine zoneNamed: called CC=2 SCAR=6.9
Pod undocumented
41 7 try {
42 7 return DateTime::TimeZone->new(name => $name);
43 }
44 catch ($error) {
45 6 ▶ return DateTime::TimeZone->new(name => 'floating') if $name eq 'local';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "local" 5 1 6
46 1 return undef;
47 }
48 23 }
49  
50 # A spec has reported a missing module in checkSpecKeys already; a Type
51 # constructed directly fails here instead.
52 ADJUST {
53 require DateTime::Format::Natural;
54 require DateTime::TimeZone;
55 $zone = __CLASS__->zoneNamed($timezone);
56 }
57  
58 4 ▶ method glSuffix() { return '=s' }
Subroutine glSuffix: called CC=1 SCAR=0.0
Pod documented
59  
60 8 ▶ method newParser(%options) {
Subroutine newParser: called CC=1 SCAR=0.0
Pod documented
61 8 return DateTime::Format::Natural->new(time_zone => $zone, %options);
62 23 }
63 }
64  
65 23 1;
66  
67 __END__
« Pad/Spec.pm ↑ Summary Pad/Result.pm »