[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.4

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

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