=================================================================== RCS file: /cvs/todotxt/Text-Todo/lib/Text/Todo/Entry.pm,v retrieving revision 1.3 retrieving revision 1.7 diff -u -r1.3 -r1.7 --- todotxt/Text-Todo/lib/Text/Todo/Entry.pm 2009/07/10 23:52:08 1.3 +++ todotxt/Text-Todo/lib/Text/Todo/Entry.pm 2009/07/13 19:05:50 1.7 @@ -1,6 +1,6 @@ package Text::Todo::Entry; -# $RedRiver: Entry.pm,v 1.2 2009/07/10 22:28:28 andrew Exp $ +# $RedRiver: Entry.pm,v 1.6 2009/07/13 17:50:37 andrew Exp $ use warnings; use strict; @@ -16,12 +16,29 @@ my %tags_of; my %priority_of; + my %completion_status_of; my %tags = ( context => q{@}, project => q{+}, ); + for my $tag ( keys %tags ) { + ## no critic strict + no strict 'refs'; # Violates use strict, but allows code generation + ## use critic + + *{ $tag . 's' } = sub { + my ($self) = @_; + return $self->_tags($tag); + }; + + *{ 'in_' . $tag } = sub { + my ( $self, $item ) = @_; + return $self->_is_in( $tag . 's', $item ); + }; + } + sub new { my ( $class, $text ) = @_; @@ -43,10 +60,12 @@ foreach my $tag ( keys %tags ) { my $symbol = quotemeta $tags{$tag}; - $tags_of{$ident}{$tag} - = { map { $_ => q{} } $text =~ / $symbol (\S+)/gxms }; + $tags_of{$ident}{$tag} = { map { $_ => q{} } + $text =~ / (?:^|\s) $symbol (\S+)/gxms }; } - ( $priority_of{$ident} ) = $text =~ /\( ([A-Z]) \)/ixms; + ( $completion_status_of{$ident} ) = $text =~ /^ \s*(x) /ixms; + ( $priority_of{$ident} ) + = $text =~ /^ (?:\s*x)? \s* \( ([A-Z]) \)/ixms; return 1; } @@ -60,10 +79,8 @@ } sub _is_in { - my ( $self, $type, $item ) = @_; - my $ident = ident($self); - - return defined first { $_ eq $item } $self->$type; + my ( $self, $tags, $item ) = @_; + return defined first { $_ eq $item } $self->$tags; } sub text { @@ -80,19 +97,13 @@ return $priority_of{$ident}; } - sub contexts { my ($self) = @_; return $self->_tags('context') } - sub projects { my ($self) = @_; return $self->_tags('project') } + sub completed { + my ($self) = @_; + my $ident = ident($self); - sub in_context { - my ( $self, $context ) = @_; - return $self->_is_in( 'contexts', $context ); + return $completion_status_of{$ident}; } - sub in_project { - my ( $self, $project ) = @_; - return $self->_is_in( 'projects', $project ); - } - sub change { my ( $self, $text ) = @_; return $self->_update_entry($text); @@ -118,8 +129,17 @@ return $self->change( join q{ }, $self->text, $addition ); } -} + sub complete { + my ($self) = @_; + if ( $self->completed ) { + return 1; + } + + return $self->change( join q{ }, 'x', $self->text ); + } + +} 1; # Magic true value required at end of module __END__ @@ -177,6 +197,10 @@ =head2 prepend =head2 append + +=head2 complete + +=head2 completed =head1 DIAGNOSTICS