line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::HWD::Work; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
App::HWD::Work - Work completed on HWD projects |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Used only by the F application. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Note that these functions are pretty fragile, and do almost no data |
12
|
|
|
|
|
|
|
checking. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
7
|
|
|
7
|
|
29654
|
use warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
389
|
|
17
|
7
|
|
|
7
|
|
47
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
277
|
|
18
|
7
|
|
|
7
|
|
1361
|
use DateTime::Format::Strptime; |
|
7
|
|
|
|
|
193397
|
|
|
7
|
|
|
|
|
7954
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 FUNCTIONS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 App::HWD::Work->parse() |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Returns an App::HWD::Work object from an input line |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub parse { |
29
|
18
|
|
|
18
|
1
|
1605
|
my $class = shift; |
30
|
18
|
|
|
|
|
33
|
my $line = shift; |
31
|
|
|
|
|
|
|
|
32
|
18
|
|
|
|
|
89
|
my @cols = split " ", $line, 5; |
33
|
18
|
50
|
|
|
|
66
|
die "Invalid work line: $line" unless @cols >= 4; |
34
|
|
|
|
|
|
|
|
35
|
18
|
|
|
|
|
51
|
my ($who, $when, $task, $hours, $comment) = @cols; |
36
|
18
|
|
|
|
|
86
|
my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' ); |
37
|
18
|
|
|
|
|
6792
|
$when = $parser->parse_datetime( $when ); |
38
|
18
|
|
|
|
|
12935
|
my $completed; |
39
|
18
|
100
|
|
|
|
57
|
if ( defined $comment ) { |
40
|
13
|
100
|
|
|
|
97
|
if ( $comment =~ s/\s*X\s*//i ) { |
41
|
10
|
|
|
|
|
18
|
$completed = 1; |
42
|
|
|
|
|
|
|
} |
43
|
13
|
|
|
|
|
45
|
$comment =~ s/^#\s*//; |
44
|
13
|
|
|
|
|
45
|
$comment =~ s/\s+$//; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
5
|
|
|
|
|
12
|
$comment = ''; |
48
|
|
|
|
|
|
|
} |
49
|
18
|
100
|
|
|
|
134
|
if ( $hours =~ s/h$// ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# nothing |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( $hours =~ /^(\d+)m$/ ) { |
53
|
1
|
|
|
|
|
4
|
$hours = $1/60; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif ( $hours != $hours+0 ) { |
56
|
0
|
|
|
|
|
0
|
die "Invalid hours: $hours\n"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
18
|
100
|
100
|
|
|
141
|
die "Invalid task: $task\n" unless ($task =~ /^\d+$/ || $task eq "^"); |
60
|
|
|
|
|
|
|
|
61
|
17
|
|
|
|
|
149
|
my $self = |
62
|
|
|
|
|
|
|
$class->new( { |
63
|
|
|
|
|
|
|
who => $who, |
64
|
|
|
|
|
|
|
when => $when, |
65
|
|
|
|
|
|
|
task => $task, |
66
|
|
|
|
|
|
|
hours => $hours, |
67
|
|
|
|
|
|
|
comment => $comment, |
68
|
|
|
|
|
|
|
completed => $completed, |
69
|
|
|
|
|
|
|
} ); |
70
|
|
|
|
|
|
|
|
71
|
17
|
|
|
|
|
154
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 App::HWD::Work->new( { args } ) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Creates a new task from the args passed in. They should include at |
77
|
|
|
|
|
|
|
least I, I and I, even if I is C. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub new { |
82
|
17
|
|
|
17
|
1
|
34
|
my $class = shift; |
83
|
17
|
|
|
|
|
26
|
my $args = shift; |
84
|
|
|
|
|
|
|
|
85
|
17
|
|
|
|
|
158
|
my $self = bless { %$args }, $class; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 $work->set( $key => $value ) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Sets the I<$key> field to I<$value>. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub set { |
96
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
97
|
0
|
|
|
|
|
0
|
my $key = shift; |
98
|
0
|
|
|
|
|
0
|
my $value = shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
die "Dupe key $key" if exists $self->{$key}; |
101
|
0
|
|
|
|
|
0
|
$self->{$key} = $value; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 $work->who() |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns who did the work |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 $work->when() |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns the when of the work as a string. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 $work->when_obj() |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns the when of the work as a DateTime object. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 $work->task() |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns the ID of the work that was worked on. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 $work->hours() |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Returns the hours spent. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 $work->completed() |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns a boolean that says whether the work was completed or not. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 $work->comment() |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Returns the comment from the file, if any. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
5
|
|
|
5
|
1
|
2249
|
sub who { return shift->{who} } |
135
|
34
|
|
|
34
|
1
|
172
|
sub task { return shift->{task} } |
136
|
5
|
|
|
5
|
1
|
27
|
sub hours { return shift->{hours} } |
137
|
17
|
|
100
|
17
|
1
|
131
|
sub completed { return shift->{completed} || 0 } |
138
|
5
|
|
|
5
|
1
|
55
|
sub comment { return shift->{comment} } |
139
|
5
|
|
|
5
|
1
|
2219
|
sub when_obj { return shift->{when} } |
140
|
|
|
|
|
|
|
sub when { |
141
|
21
|
|
|
21
|
1
|
268
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
21
|
100
|
|
|
|
103
|
my $obj = $self->{when} or return ''; |
144
|
|
|
|
|
|
|
|
145
|
19
|
|
|
|
|
1022
|
return $obj->strftime( "%F" ); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Andy Lester, C<< >> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Copyright 2006 Andy Lester, all rights reserved. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
157
|
|
|
|
|
|
|
under the same terms as Perl itself. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; # End of App::HWD::Task |