=================================================================== RCS file: /cvs/todotxt/Text-Todo/lib/Text/Todo/Entry.pm,v retrieving revision 1.3 retrieving revision 1.5 diff -u -r1.3 -r1.5 --- 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/11 17:02:18 1.5 @@ -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.4 2009/07/11 15:58:50 andrew Exp $ use warnings; use strict; @@ -22,6 +22,22 @@ 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 ) = @_; @@ -46,7 +62,7 @@ $tags_of{$ident}{$tag} = { map { $_ => q{} } $text =~ / $symbol (\S+)/gxms }; } - ( $priority_of{$ident} ) = $text =~ /\( ([A-Z]) \)/ixms; + ( $priority_of{$ident} ) = $text =~ /^ \s* \( ([A-Z]) \)/ixms; return 1; } @@ -60,10 +76,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 { @@ -78,19 +92,6 @@ my $ident = ident($self); return $priority_of{$ident}; - } - - sub contexts { my ($self) = @_; return $self->_tags('context') } - sub projects { my ($self) = @_; return $self->_tags('project') } - - sub in_context { - my ( $self, $context ) = @_; - return $self->_is_in( 'contexts', $context ); - } - - sub in_project { - my ( $self, $project ) = @_; - return $self->_is_in( 'projects', $project ); } sub change {