File Coverage

blib/lib/XML/SRS/TimeStamp/Role.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1              
2             package XML::SRS::TimeStamp::Role;
3              
4 1     1   1430 use 5.010;
  1         2  
  1         32  
5 1     1   31 use XML::SRS::Date;
  0            
  0            
6             use XML::SRS::Time;
7             use Moose::Role;
8             use MooseX::Method::Signatures;
9              
10             use MooseX::Timestamp qw();
11             use MooseX::TimestampTZ
12             timestamptz => { -as => "_timestamptz" },
13             epoch => { -as => "_epoch" },
14             ;
15              
16             has 'timestamp' =>
17             is => "rw",
18             isa => "Timestamp",
19             coerce => 1,
20             lazy => 1,
21             default => sub {
22             my $self = shift;
23             sprintf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
24             $self->year, $self->month, $self->day,
25             $self->hour, $self->minute, $self->second//0,
26             );
27             },
28             ;
29              
30             method buildargs_timestamp( $inv: Timestamp $timestamp is coerce ) {
31             my ($date, $time) = split " ", $timestamp;
32             ($inv->buildargs_time($time), $inv->buildargs_date($date));
33             }
34              
35             method buildargs_timestamptz( $inv: TimestampTZ $timestamptz is coerce ) {
36             $timestamptz =~ m{
37             (?<ymd>\d+-\d+-\d+)
38             \s(?<hms>\d+:\d+:\d+)
39             (?: (?<utc>Z) | (?<offset> [+-]\d{2} (?::?\d{2})? )
40             )}x or warn "$timestamptz didn't match";
41             my $hms = $+{hms};
42             my $ymd = $+{ymd};
43             my $offset = $+{utc} ? "+00:00" : $+{offset};
44             ($inv->buildargs_time($hms, $offset),
45             $inv->buildargs_date($ymd));
46             }
47              
48             method buildargs_epoch( $inv: time_t $epoch is coerce ) {
49             $inv->buildargs_timestamptz(_timestamptz $epoch);
50             }
51              
52             has 'timestamptz' =>
53             is => "rw",
54             isa => "TimestampTZ",
55             coerce => 1,
56             lazy => 1,
57             default => sub {
58             my $self = shift;
59             sprintf("%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s",
60             $self->year, $self->month, $self->day,
61             $self->hour, $self->minute, $self->second//0,
62             $self->tz_offset//"",
63             );
64             },
65             ;
66              
67             has 'epoch' =>
68             is => "rw",
69             isa => "time_t",
70             coerce => 1,
71             lazy => 1,
72             default => sub {
73             my $self = shift;
74             _epoch $self->timestamptz;
75             },
76             ;
77              
78             with 'XML::SRS::Date', 'XML::SRS::Time';
79              
80             1;