[BACK]Return to Entry.pm CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo / lib / Text / Todo

Diff for /todotxt/Text-Todo/lib/Text/Todo/Entry.pm between version 1.3 and 1.7

version 1.3, 2009/07/10 23:52:08 version 1.7, 2009/07/13 19:05:50
Line 1 
Line 1 
 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.6 2009/07/13 17:50:37 andrew Exp $
   
 use warnings;  use warnings;
 use strict;  use strict;
Line 16 
Line 16 
   
     my %tags_of;      my %tags_of;
     my %priority_of;      my %priority_of;
       my %completion_status_of;
   
     my %tags = (      my %tags = (
         context => q{@},          context => q{@},
         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 ) = @_;
   
Line 43 
Line 60 
   
         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;          ( $completion_status_of{$ident} ) = $text =~ /^ \s*(x) /ixms;
           ( $priority_of{$ident} )
               = $text =~ /^ (?:\s*x)? \s* \( ([A-Z]) \)/ixms;
   
         return 1;          return 1;
     }      }
Line 60 
Line 79 
     }      }
   
     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 {
Line 80 
Line 97 
         return $priority_of{$ident};          return $priority_of{$ident};
     }      }
   
     sub contexts { my ($self) = @_; return $self->_tags('context') }      sub completed {
     sub projects { my ($self) = @_; return $self->_tags('project') }          my ($self) = @_;
           my $ident = ident($self);
   
     sub in_context {          return $completion_status_of{$ident};
         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 {
         my ( $self, $text ) = @_;          my ( $self, $text ) = @_;
         return $self->_update_entry($text);          return $self->_update_entry($text);
Line 118 
Line 129 
         return $self->change( join q{ }, $self->text, $addition );          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  1;    # Magic true value required at end of module
 __END__  __END__
   
Line 177 
Line 197 
 =head2 prepend  =head2 prepend
   
 =head2 append  =head2 append
   
   =head2 complete
   
   =head2 completed
   
   
 =head1 DIAGNOSTICS  =head1 DIAGNOSTICS

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>