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

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

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