=================================================================== RCS file: /cvs/todotxt/Text-Todo/lib/Text/Todo/Entry.pm,v retrieving revision 1.1 retrieving revision 1.3 diff -u -r1.1 -r1.3 --- todotxt/Text-Todo/lib/Text/Todo/Entry.pm 2009/07/10 23:26:14 1.1 +++ todotxt/Text-Todo/lib/Text/Todo/Entry.pm 2009/07/10 23:52:08 1.3 @@ -1,6 +1,6 @@ package Text::Todo::Entry; -# $RedRiver$ +# $RedRiver: Entry.pm,v 1.2 2009/07/10 22:28:28 andrew Exp $ use warnings; use strict; @@ -14,10 +14,14 @@ { my %text_of; - my %contexts_of; - my %projects_of; + my %tags_of; my %priority_of; + my %tags = ( + context => q{@}, + project => q{+}, + ); + sub new { my ( $class, $text ) = @_; @@ -37,44 +41,38 @@ $text_of{$ident} = $text; - %{ $contexts_of{$ident} } = map { $_ => q{} } $text =~ /\@ (\S+)/gxms; - %{ $projects_of{$ident} } = map { $_ => q{} } $text =~ /\+ (\S+)/gxms; + foreach my $tag ( keys %tags ) { + my $symbol = quotemeta $tags{$tag}; + $tags_of{$ident}{$tag} + = { map { $_ => q{} } $text =~ / $symbol (\S+)/gxms }; + } ( $priority_of{$ident} ) = $text =~ /\( ([A-Z]) \)/ixms; return 1; } - sub text { - my ($self) = @_; + sub _tags { + my ( $self, $tag ) = @_; my $ident = ident($self); - return $text_of{$ident}; + my @tags = sort keys %{ $tags_of{$ident}{$tag} }; + return wantarray ? @tags : \@tags; } - sub contexts { - my ($self) = @_; + sub _is_in { + my ( $self, $type, $item ) = @_; my $ident = ident($self); - return sort keys %{ $contexts_of{$ident} }; + return defined first { $_ eq $item } $self->$type; } - sub in_context { - my ( $self, $context ) = @_; - return $self->_is_in( $context, 'contexts' ); - } - - sub projects { + sub text { my ($self) = @_; my $ident = ident($self); - return sort keys %{ $projects_of{$ident} }; + return $text_of{$ident}; } - sub in_project { - my ( $self, $project ) = @_; - return $self->_is_in( $project, 'projects' ); - } - sub priority { my ($self) = @_; my $ident = ident($self); @@ -82,11 +80,17 @@ return $priority_of{$ident}; } - sub _is_in { - my ( $self, $item, $type ) = @_; - my $ident = ident($self); + sub contexts { my ($self) = @_; return $self->_tags('context') } + sub projects { my ($self) = @_; return $self->_tags('project') } - return defined first { $_ eq $item } $self->$type; + 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 {