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