JobLog/Log/Note.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 109 CC 4 SCAR 12.8
CC
4
Cov
0%
cmp
12.0
intersects
6.0
new
2.0
CRAP 3.6
1 package App::JobLog::Log::Note;
2 $App::JobLog::Log::Note::VERSION = '1.042';
3 # ABSTRACT: timestamped annotation in log
4  
5  
6 use Modern::Perl;
7 use Class::Autouse qw{DateTime};
8 use autouse 'App::JobLog::Time' => qw(now);
9 use autouse 'Carp' => qw(carp);
10  
11 # for debugging
12 use overload '""' => sub {
13 $_[0]->data->to_string;
14 };
15 use overload 'bool' => sub { 1 };
16  
17  
18 sub new {
19 my ( $class, $logline ) = @_;
20 $class = ref $class || $class;
21 my $self = bless { log => $logline }, $class;
22 return $self;
23 }
24  
25  
26 sub clone {
27 my ($self) = @_;
28 my $clone = $self->new( $self->data->clone );
29 return $clone;
30 }
31  
32  
33 sub data {
34 $_[0]->{log};
35 }
36  
37  
38 sub start : lvalue {
39 $_[0]->data->time;
40 }
41  
42  
43 sub tags : lvalue {
44 $_[0]->data->{tags};
45 }
46  
47  
48 sub tagged { !!@{ $_[0]->tags } }
49  
50  
51 sub tag_list { @{ $_[0]->tags } }
52  
53  
54 sub describe {
55 my ($self) = @_;
56 join '; ', @{ $self->data->description };
57 }
58  
59  
60 sub exists_tag {
61 my ( $self, @tags ) = @_;
62 $self->data->exists_tag(@tags);
63 }
64  
65  
66 sub all_tags {
67 my ( $self, @tags ) = @_;
68 $self->data->all_tags(@tags);
69 }
70  
71  
72 sub cmp {
73 my ( $self, $other ) = @_;
74 carp 'argument must also be time' unless $other->isa(__PACKAGE__);
75  
76 # defer to subclass sort order if other is a subclass and self isn't
77 return -$other->cmp($self)
78 if ref $self eq __PACKAGE__ && ref $other ne __PACKAGE__;
79  
80 return DateTime->compare( $self->start, $other->start );
81 }
82  
83  
84 sub split_days {
85 return $_[0];
86 }
87  
88  
89 sub intersects {
90 my ( $self, $other ) = @_;
91 if ( $other->can('end') ) {
92 return $self->start >= $other->start && $self->start < $other->end;
93 }
94 return $self->start == $other->start;
95 }
96  
97  
98 sub is_note {
99 shift->{log}->is_note
100 }
101  
102  
103 sub is_open { 0 }
104  
105 1;
106  
107 __END__