| hwd documentation | Contained in the hwd distribution. |
App::HWD::Work - Work completed on HWD projects
Used only by the hwd application.
Note that these functions are pretty fragile, and do almost no data checking.
Returns an App::HWD::Work object from an input line
Creates a new task from the args passed in. They should include at
least level, name and id, even if id is undef.
Sets the $key field to $value.
Returns who did the work
Returns the when of the work as a string.
Returns the when of the work as a DateTime object.
Returns the ID of the work that was worked on.
Returns the hours spent.
Returns a boolean that says whether the work was completed or not.
Returns the comment from the file, if any.
Andy Lester, <andy at petdance.com>
Copyright 2006 Andy Lester, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| hwd documentation | Contained in the hwd distribution. |
package App::HWD::Work;
use warnings; use strict; use DateTime::Format::Strptime;
sub parse { my $class = shift; my $line = shift; my @cols = split " ", $line, 5; die "Invalid work line: $line" unless @cols >= 4; my ($who, $when, $task, $hours, $comment) = @cols; my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' ); $when = $parser->parse_datetime( $when ); my $completed; if ( defined $comment ) { if ( $comment =~ s/\s*X\s*//i ) { $completed = 1; } $comment =~ s/^#\s*//; $comment =~ s/\s+$//; } else { $comment = ''; } if ( $hours =~ s/h$// ) { # nothing } elsif ( $hours =~ /^(\d+)m$/ ) { $hours = $1/60; } elsif ( $hours != $hours+0 ) { die "Invalid hours: $hours\n"; } die "Invalid task: $task\n" unless ($task =~ /^\d+$/ || $task eq "^"); my $self = $class->new( { who => $who, when => $when, task => $task, hours => $hours, comment => $comment, completed => $completed, } ); return $self; }
sub new { my $class = shift; my $args = shift; my $self = bless { %$args }, $class; }
sub set { my $self = shift; my $key = shift; my $value = shift; die "Dupe key $key" if exists $self->{$key}; $self->{$key} = $value; }
sub who { return shift->{who} } sub task { return shift->{task} } sub hours { return shift->{hours} } sub completed { return shift->{completed} || 0 } sub comment { return shift->{comment} } sub when_obj { return shift->{when} } sub when { my $self = shift; my $obj = $self->{when} or return ''; return $obj->strftime( "%F" ); }
1; # End of App::HWD::Task