start_day.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 1 totaltotal 91.1% 62 / 68 CC 2 SCAR 2.1
CC
2
Cov
94%
__ANON__
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.2
« timestamp.pm ↑ Summary end_day.pm »
1 package Catmandu::Fix::start_day;
2 2 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Catmandu::Util qw(:is :check :array);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = "0.0132";
10  
11 2 with 'Catmandu::Fix::Base';
12  
13 2 has path => (
14 is => 'ro' ,
15 required => 1
16 );
17 has add => (
18 is => 'ro',
19 2 ▶ isa => sub { check_integer($_[0]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 required => 0,
21 lazy => 1,
22 1 ▶ default => sub { 0; }
Subroutine __ANON__: called CC=1 SCAR=0.0
23 2 );
24 has time_zone => (
25 is => 'ro',
26 required => 1,
27 2 ▶ isa => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 check_string($_[0]);
29 },
30 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 "UTC"
32 }
33 2 );
34 has pattern => (
35 is => 'ro',
36 required => 1,
37 2 ▶ isa => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 2 check_string($_[0]);
39 },
40 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 0 "%FT%T.%NZ"
42 }
43 2 );
44  
45 2 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 2 my($orig,$class,$path,%args) = @_;
47 2 $orig->($class,
48 path => $path,
49 %args
50 );
51 2 };
52  
53 2 ▶sub emit {
Subroutine emit: called CC=1 SCAR=0.0
Pod undocumented
54 2 my($self,$fixer) = @_;
55  
56 2 my $path = $fixer->split_path($self->path());
57 2 ▶ my $start_day = $fixer->capture(sub{
Subroutine __ANON__: called CC=2 SCAR=7.0
58 2 my $skip = shift;
59 #we need to set the time zone first before doing any math!
60 2 my $d = DateTime->now->set_time_zone($self->time_zone)->truncate(to => "day");
61 2 ▶ if(is_integer($skip)){
Branch: 1 branch
BranchTrueFalseTotal
if (is_integer($skip)) 2 0 2
62 2 $d->add(days => $skip);
63 }
64 2 $d;
65 2 });
66  
67 2 ▶ $fixer->emit_create_path($fixer->var,$path,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
68  
69 2 my $var = shift;
70  
71 2 my $d = $fixer->generate_var();
72 2 my $p = $fixer->emit_declare_vars($d);
73 2 $p .= " $d = ${start_day}->(".$self->add().");";
74 2 $p .= " ${var} = DateTime::Format::Strptime::strftime('".$self->pattern()."',$d);";
75  
76 2 $p;
77  
78 2 });
79  
80 }
81  
82 2 1;
83 __END__
« timestamp.pm ↑ Summary end_day.pm »