| version 1.1, 2009/07/10 23:26:14 |
version 1.4, 2009/07/11 16:58:50 |
|
|
| package Text::Todo::Entry; |
package Text::Todo::Entry; |
| |
|
| # $RedRiver$ |
# $RedRiver: Entry.pm,v 1.3 2009/07/10 22:52:08 andrew Exp $ |
| |
|
| use warnings; |
use warnings; |
| use strict; |
use strict; |
|
|
| { |
{ |
| my %text_of; |
my %text_of; |
| |
|
| my %contexts_of; |
my %tags_of; |
| my %projects_of; |
|
| my %priority_of; |
my %priority_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 { |
sub new { |
| my ( $class, $text ) = @_; |
my ( $class, $text ) = @_; |
| |
|
|
|
| |
|
| $text_of{$ident} = $text; |
$text_of{$ident} = $text; |
| |
|
| %{ $contexts_of{$ident} } = map { $_ => q{} } $text =~ /\@ (\S+)/gxms; |
foreach my $tag ( keys %tags ) { |
| %{ $projects_of{$ident} } = map { $_ => q{} } $text =~ /\+ (\S+)/gxms; |
my $symbol = quotemeta $tags{$tag}; |
| ( $priority_of{$ident} ) = $text =~ /\( ([A-Z]) \)/ixms; |
$tags_of{$ident}{$tag} |
| |
= { map { $_ => q{} } $text =~ / $symbol (\S+)/gxms }; |
| |
} |
| |
( $priority_of{$ident} ) = $text =~ /^ \s* \( ([A-Z]) \)/ixms; |
| |
|
| return 1; |
return 1; |
| } |
} |
| |
|
| sub text { |
sub _tags { |
| my ($self) = @_; |
my ( $self, $tag ) = @_; |
| my $ident = ident($self); |
my $ident = ident($self); |
| |
|
| return $text_of{$ident}; |
my @tags = sort keys %{ $tags_of{$ident}{$tag} }; |
| |
return wantarray ? @tags : \@tags; |
| } |
} |
| |
|
| sub contexts { |
sub _is_in { |
| my ($self) = @_; |
my ( $self, $type, $item ) = @_; |
| my $ident = ident($self); |
my $ident = ident($self); |
| |
|
| return sort keys %{ $contexts_of{$ident} }; |
return defined first { $_ eq $item } $self->$type; |
| } |
} |
| |
|
| sub in_context { |
sub text { |
| my ( $self, $context ) = @_; |
|
| return $self->_is_in( $context, 'contexts' ); |
|
| } |
|
| |
|
| sub projects { |
|
| my ($self) = @_; |
my ($self) = @_; |
| my $ident = ident($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 { |
sub priority { |
| my ($self) = @_; |
my ($self) = @_; |
| my $ident = ident($self); |
my $ident = ident($self); |
| |
|
| return $priority_of{$ident}; |
return $priority_of{$ident}; |
| } |
|
| |
|
| sub _is_in { |
|
| my ( $self, $item, $type ) = @_; |
|
| my $ident = ident($self); |
|
| |
|
| return defined first { $_ eq $item } $self->$type; |
|
| } |
} |
| |
|
| sub change { |
sub change { |