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

Annotation of todotxt/Text-Todo/lib/Text/Todo/Entry.pm, Revision 1.3

1.1       andrew      1: package Text::Todo::Entry;
                      2:
1.3     ! andrew      3: # $RedRiver: Entry.pm,v 1.2 2009/07/10 22:28:28 andrew Exp $
1.1       andrew      4:
                      5: use warnings;
                      6: use strict;
                      7: use Carp;
                      8:
                      9: use Class::Std::Utils;
                     10: use List::Util qw/ first /;
                     11:
                     12: use version; our $VERSION = qv('0.0.1');
                     13:
                     14: {
                     15:     my %text_of;
                     16:
1.3     ! andrew     17:     my %tags_of;
1.1       andrew     18:     my %priority_of;
                     19:
1.3     ! andrew     20:     my %tags = (
        !            21:         context => q{@},
        !            22:         project => q{+},
        !            23:     );
        !            24:
1.1       andrew     25:     sub new {
                     26:         my ( $class, $text ) = @_;
                     27:
                     28:         my $self = bless anon_scalar(), $class;
                     29:         my $ident = ident($self);
                     30:
                     31:         $self->_update_entry($text);
                     32:
                     33:         return $self;
                     34:     }
                     35:
                     36:     sub _update_entry {
                     37:         my ( $self, $text ) = @_;
                     38:         my $ident = ident($self);
                     39:
                     40:         $text = defined $text ? $text : q{};
                     41:
                     42:         $text_of{$ident} = $text;
                     43:
1.3     ! andrew     44:         foreach my $tag ( keys %tags ) {
        !            45:             my $symbol = quotemeta $tags{$tag};
        !            46:             $tags_of{$ident}{$tag}
        !            47:                 = { map { $_ => q{} } $text =~ / $symbol  (\S+)/gxms };
        !            48:         }
1.1       andrew     49:         ( $priority_of{$ident} ) = $text =~ /\( ([A-Z]) \)/ixms;
                     50:
                     51:         return 1;
                     52:     }
                     53:
1.3     ! andrew     54:     sub _tags {
        !            55:         my ( $self, $tag ) = @_;
1.1       andrew     56:         my $ident = ident($self);
                     57:
1.3     ! andrew     58:         my @tags = sort keys %{ $tags_of{$ident}{$tag} };
        !            59:         return wantarray ? @tags : \@tags;
1.1       andrew     60:     }
                     61:
1.3     ! andrew     62:     sub _is_in {
        !            63:         my ( $self, $type, $item ) = @_;
1.1       andrew     64:         my $ident = ident($self);
                     65:
1.3     ! andrew     66:         return defined first { $_ eq $item } $self->$type;
1.1       andrew     67:     }
                     68:
1.3     ! andrew     69:     sub text {
1.1       andrew     70:         my ($self) = @_;
                     71:         my $ident = ident($self);
                     72:
1.3     ! andrew     73:         return $text_of{$ident};
1.1       andrew     74:     }
                     75:
                     76:     sub priority {
                     77:         my ($self) = @_;
                     78:         my $ident = ident($self);
                     79:
                     80:         return $priority_of{$ident};
                     81:     }
                     82:
1.3     ! andrew     83:     sub contexts { my ($self) = @_; return $self->_tags('context') }
        !            84:     sub projects { my ($self) = @_; return $self->_tags('project') }
        !            85:
        !            86:     sub in_context {
        !            87:         my ( $self, $context ) = @_;
        !            88:         return $self->_is_in( 'contexts', $context );
        !            89:     }
1.1       andrew     90:
1.3     ! andrew     91:     sub in_project {
        !            92:         my ( $self, $project ) = @_;
        !            93:         return $self->_is_in( 'projects', $project );
1.1       andrew     94:     }
                     95:
                     96:     sub change {
                     97:         my ( $self, $text ) = @_;
                     98:         return $self->_update_entry($text);
                     99:     }
                    100:
                    101:     sub prepend {
                    102:         my ( $self, $addition ) = @_;
                    103:
                    104:         my $new = $self->text;
                    105:
                    106:         if ( my $priority = $self->priority ) {
                    107:             $new =~ s/^( \s* \( $priority \))/$1 $addition/xms;
                    108:         }
                    109:         else {
                    110:             $new = join q{ }, $addition, $new;
                    111:         }
                    112:
                    113:         return $self->change($new);
                    114:     }
                    115:
                    116:     sub append {
                    117:         my ( $self, $addition ) = @_;
                    118:         return $self->change( join q{ }, $self->text, $addition );
                    119:     }
                    120:
                    121: }
                    122:
                    123: 1;    # Magic true value required at end of module
                    124: __END__
                    125:
                    126: =head1 NAME
                    127:
                    128: Text::Todo::Entry - [One line description of module's purpose here]
                    129:
                    130:
                    131: =head1 VERSION
                    132:
                    133: This document describes Text::Todo::Entry version 0.0.1
                    134:
                    135:
                    136: =head1 SYNOPSIS
                    137:
                    138:     use Text::Todo::Entry;
                    139:
                    140: =for author to fill in:
                    141:     Brief code example(s) here showing commonest usage(s).
                    142:     This section will be as far as many users bother reading
                    143:     so make it as educational and exeplary as possible.
                    144:
                    145:
                    146: =head1 DESCRIPTION
                    147:
                    148: =for author to fill in:
                    149:     Write a full description of the module and its features here.
                    150:     Use subsections (=head2, =head3) as appropriate.
                    151:
                    152:
                    153: =head1 INTERFACE
                    154:
                    155: =for author to fill in:
                    156:     Write a separate section listing the public components of the modules
                    157:     interface. These normally consist of either subroutines that may be
                    158:     exported, or methods that may be called on objects belonging to the
                    159:     classes provided by the module.
                    160:
                    161: =head2 new
                    162:
                    163: =head2 text
                    164:
                    165: =head2 priority
                    166:
                    167: =head2 contexts
                    168:
                    169: =head2 in_context
                    170:
                    171: =head2 projects
                    172:
                    173: =head2 in_project
                    174:
                    175: =head2 change
                    176:
                    177: =head2 prepend
                    178:
                    179: =head2 append
                    180:
                    181:
                    182: =head1 DIAGNOSTICS
                    183:
                    184: =for author to fill in:
                    185:     List every single error and warning message that the module can
                    186:     generate (even the ones that will "never happen"), with a full
                    187:     explanation of each problem, one or more likely causes, and any
                    188:     suggested remedies.
                    189:
                    190: =over
                    191:
                    192: =item C<< Error message here, perhaps with %s placeholders >>
                    193:
                    194: [Description of error here]
                    195:
                    196: =item C<< Another error message here >>
                    197:
                    198: [Description of error here]
                    199:
                    200: [Et cetera, et cetera]
                    201:
                    202: =back
                    203:
                    204:
                    205: =head1 CONFIGURATION AND ENVIRONMENT
                    206:
                    207: =for author to fill in:
                    208:     A full explanation of any configuration system(s) used by the
                    209:     module, including the names and locations of any configuration
                    210:     files, and the meaning of any environment variables or properties
                    211:     that can be set. These descriptions must also include details of any
                    212:     configuration language used.
                    213:
                    214: Text::Todo::Entry requires no configuration files or environment variables.
                    215:
                    216:
                    217: =head1 DEPENDENCIES
                    218:
                    219: =for author to fill in:
                    220:     A list of all the other modules that this module relies upon,
                    221:     including any restrictions on versions, and an indication whether
                    222:     the module is part of the standard Perl distribution, part of the
                    223:     module's distribution, or must be installed separately. ]
                    224:
                    225: None.
                    226:
                    227:
                    228: =head1 INCOMPATIBILITIES
                    229:
                    230: =for author to fill in:
                    231:     A list of any modules that this module cannot be used in conjunction
                    232:     with. This may be due to name conflicts in the interface, or
                    233:     competition for system or program resources, or due to internal
                    234:     limitations of Perl (for example, many modules that use source code
                    235:     filters are mutually incompatible).
                    236:
                    237: None reported.
                    238:
                    239:
                    240: =head1 BUGS AND LIMITATIONS
                    241:
                    242: =for author to fill in:
                    243:     A list of known problems with the module, together with some
                    244:     indication Whether they are likely to be fixed in an upcoming
                    245:     release. Also a list of restrictions on the features the module
                    246:     does provide: data types that cannot be handled, performance issues
                    247:     and the circumstances in which they may arise, practical
                    248:     limitations on the size of data sets, special cases that are not
                    249:     (yet) handled, etc.
                    250:
                    251: No bugs have been reported.
                    252:
                    253: Please report any bugs or feature requests to
                    254: C<bug-text-todo@rt.cpan.org>, or through the web interface at
                    255: L<http://rt.cpan.org>.
                    256:
                    257:
                    258: =head1 AUTHOR
                    259:
                    260: Andrew Fresh  C<< <andrew@cpan.org> >>
                    261:
                    262:
                    263: =head1 LICENSE AND COPYRIGHT
                    264:
                    265: Copyright (c) 2009, Andrew Fresh C<< <andrew@cpan.org> >>. All rights reserved.
                    266:
                    267: This module is free software; you can redistribute it and/or
                    268: modify it under the same terms as Perl itself. See L<perlartistic>.
                    269:
                    270:
                    271: =head1 DISCLAIMER OF WARRANTY
                    272:
                    273: BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
                    274: FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
                    275: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
                    276: PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
                    277: EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                    278: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
                    279: ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
                    280: YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
                    281: NECESSARY SERVICING, REPAIR, OR CORRECTION.
                    282:
                    283: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
                    284: WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
                    285: REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
                    286: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
                    287: OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
                    288: THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
                    289: RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
                    290: FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
                    291: SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
                    292: SUCH DAMAGES.

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