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
|
|
47861
|
use warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
291
|
|
17
|
7
|
|
|
7
|
|
77
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
250
|
|
18
|
7
|
|
|
7
|
|
968
|
use DateTime::Format::Strptime; |
|
7
|
|
|
|
|
249862
|
|
|
7
|
|
|
|
|
4674
|
|
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
|
2264
|
my $class = shift; |
30
|
18
|
|
|
|
|
34
|
my $line = shift; |
31
|
|
|
|
|
|
|
|
32
|
18
|
|
|
|
|
93
|
my @cols = split " ", $line, 5; |
33
|
18
|
50
|
|
|
|
69
|
die "Invalid work line: $line" unless @cols >= 4; |
34
|
|
|
|
|
|
|
|
35
|
18
|
|
|
|
|
50
|
my ($who, $when, $task, $hours, $comment) = @cols; |
36
|
18
|
|
|
|
|
101
|
my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' ); |
37
|
18
|
|
|
|
|
7429
|
$when = $parser->parse_datetime( $when ); |
38
|
18
|
|
|
|
|
13134
|
my $completed; |
39
|
18
|
100
|
|
|
|
63
|
if ( defined $comment ) { |
40
|
13
|
100
|
|
|
|
103
|
if ( $comment =~ s/\s*X\s*//i ) { |
41
|
10
|
|
|
|
|
1052
|
$completed = 1; |
42
|
|
|
|
|
|
|
} |
43
|
13
|
|
|
|
|
60
|
$comment =~ s/^#\s*//; |
44
|
13
|
|
|
|
|
60
|
$comment =~ s/\s+$//; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
5
|
|
|
|
|
13
|
$comment = ''; |
48
|
|
|
|
|
|
|
} |
49
|
18
|
100
|
|
|
|
153
|
if ( $hours =~ s/h$// ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# nothing |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( $hours =~ /^(\d+)m$/ ) { |
53
|
1
|
|
|
|
|
6
|
$hours = $1/60; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif ( $hours != $hours+0 ) { |
56
|
0
|
|
|
|
|
0
|
die "Invalid hours: $hours\n"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
18
|
100
|
100
|
|
|
159
|
die "Invalid task: $task\n" unless ($task =~ /^\d+$/ || $task eq "^"); |
60
|
|
|
|
|
|
|
|
61
|
17
|
|
|
|
|
146
|
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
|
|
|
|
|
244
|
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
|
28
|
my $class = shift; |
83
|
17
|
|
|
|
|
28
|
my $args = shift; |
84
|
|
|
|
|
|
|
|
85
|
17
|
|
|
|
|
241
|
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
|
3666
|
sub who { return shift->{who} } |
135
|
34
|
|
|
34
|
1
|
175
|
sub task { return shift->{task} } |
136
|
5
|
|
|
5
|
1
|
30
|
sub hours { return shift->{hours} } |
137
|
17
|
|
100
|
17
|
1
|
140
|
sub completed { return shift->{completed} || 0 } |
138
|
5
|
|
|
5
|
1
|
30
|
sub comment { return shift->{comment} } |
139
|
5
|
|
|
5
|
1
|
2961
|
sub when_obj { return shift->{when} } |
140
|
|
|
|
|
|
|
sub when { |
141
|
21
|
|
|
21
|
1
|
230
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
21
|
100
|
|
|
|
103
|
my $obj = $self->{when} or return ''; |
144
|
|
|
|
|
|
|
|
145
|
19
|
|
|
|
|
882
|
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 |