version 1.3, 2009/07/10 23:52:08 |
version 1.6, 2009/07/13 18:50:37 |
|
|
package Text::Todo::Entry; |
package Text::Todo::Entry; |
|
|
# $RedRiver: Entry.pm,v 1.2 2009/07/10 22:28:28 andrew Exp $ |
# $RedRiver: Entry.pm,v 1.5 2009/07/11 16:02:18 andrew Exp $ |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
|
|
project => 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 ) = @_; |
|
|
|
|
|
|
foreach my $tag ( keys %tags ) { |
foreach my $tag ( keys %tags ) { |
my $symbol = quotemeta $tags{$tag}; |
my $symbol = quotemeta $tags{$tag}; |
$tags_of{$ident}{$tag} |
$tags_of{$ident}{$tag} = { map { $_ => q{} } |
= { map { $_ => q{} } $text =~ / $symbol (\S+)/gxms }; |
$text =~ / (?:^|\s) $symbol (\S+)/gxms }; |
} |
} |
( $priority_of{$ident} ) = $text =~ /\( ([A-Z]) \)/ixms; |
( $priority_of{$ident} ) = $text =~ /^ \s* \( ([A-Z]) \)/ixms; |
|
|
return 1; |
return 1; |
} |
} |
|
|
} |
} |
|
|
sub _is_in { |
sub _is_in { |
my ( $self, $type, $item ) = @_; |
my ( $self, $tags, $item ) = @_; |
my $ident = ident($self); |
return defined first { $_ eq $item } $self->$tags; |
|
|
return defined first { $_ eq $item } $self->$type; |
|
} |
} |
|
|
sub text { |
sub text { |
|
|
my $ident = ident($self); |
my $ident = ident($self); |
|
|
return $priority_of{$ident}; |
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 { |
sub change { |