Annotation of todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Actions/PUT.pm, Revision 1.2
1.1 andrew 1: package Text::Todo::REST::API::Actions::PUT;
2:
1.2 ! andrew 3: # $AFresh1: PUT.pm,v 1.1 2010/02/18 05:34:31 andrew Exp $
1.1 andrew 4:
5: use warnings;
6: use strict;
7: use Carp;
8:
9: use Class::Std::Utils;
10: use Digest::MD5 qw/ md5_hex /;
11:
12: use version; our $VERSION = qv('0.0.1');
13:
14: {
15: my @attr_refs = \();
16:
17: sub new {
18: my ( $class, $options ) = @_;
19:
20: my $self = bless anon_scalar(), $class;
21: my $ident = ident($self);
22:
23: return $self;
24: }
25:
26: #sub put_entry_done {
27: #my ( $self, $todo, $key ) = @_;
28: #my $entry = $self->put_entry( $todo, $key );
29: #return $todo->list->[ $entry->{line} - 1 ]->done;
30: #}
31:
32: sub put_entry {
33: my ( $self, $todo, $options ) = @_;
34: my $id = $options->{entry};
35:
36: my $new_text;
37: VALUE: foreach my $k qw( text value ) {
38: if ( exists $options->{$k} ) {
39: $new_text = $options->{$k};
40: last VALUE;
41: }
42: }
43:
44: my $list = $todo->list;
45:
46: my $line = 0;
47: my $entry;
48: if ( $id =~ /^[[:xdigit:]]{32}$/xms ) {
49: my $search = lc $id;
50:
51: ENTRY: foreach my $e ( @{$list} ) {
52: $line++;
53: if ( $search eq md5_hex( $e->text ) ) {
54: $entry = $e;
55: last ENTRY;
56: }
57: }
58: }
59: elsif ( $id =~ /^\d+$/xms ) {
60: $line = $id;
61: $entry = $list->[ $id - 1 ];
62: }
63:
64: if ($entry && $options->{md5}) {
65: if (md5_hex($entry->text) ne lc($options->{md5})) {
66: $entry = undef;
67: }
68: }
69:
70: if ( defined $new_text ) {
71: if ($entry) {
72: $entry->replace($new_text);
73: }
74: else {
75: $entry = $todo->add($new_text);
76: $line = 1 + @{$list};
77: }
78:
79: $todo->save;
80:
81: return {
82: line => $line,
83: md5 => md5_hex( $entry->text ),
84: text => $entry->text,
85: done => $entry->done,
86: };
87: }
88:
89: return $self->_fail("Unable to find entry [$id]!");
90: }
91:
92: #sub put_list {
93: #my ( $self, $todo ) = @_;
94: #die "PUT_LIST";
95: #}
96:
97: #sub put_files {
98: #my ( $self, $todo, $options ) = @_;
99: #die "PUT_FILES";
100:
101: #my $dir = $todo->file('todo_dir');
102:
103: #if ( !$dir ) {
104: #return $self->_fail('Unable to find todo_dir');
105: #}
106:
107: #my $file_regex = $options->{file_regex};
108:
109: #opendir my $dh, $dir or croak "Couldn't opendir: $!";
110: #my @files = grep {m/$file_regex/xms} readdir $dh;
111: #closedir $dh;
112:
113: #return \@files;
114: #}
115:
116: sub _which_key {
117: my ( $self, $key, $type ) = @_;
118:
119: return if !defined $key;
120:
121: if ( ref $key eq 'ARRAY' ) {
122: $key = $key->[0];
123: }
124: elsif ( ref $key eq 'HASH' ) {
125: $key = $key->{$type};
126: }
127:
128: return $key;
129: }
130:
131: sub _fail {
132: my ( $self, @message ) = @_;
133: croak(@message);
134: }
135:
136: sub DESTROY {
137: my ($self) = @_;
138: my $ident = ident $self;
139: foreach my $attr_ref (@attr_refs) {
140: delete $attr_ref->{$ident};
141: }
142: }
143: }
144: 1; # Magic true value required at end of module
145: __END__
146:
147: =head1 NAME
148:
149: Text::Todo::REST::API - [One line description of module's purpose here]
150:
151:
152: =head1 VERSION
153:
154: This document describes Text::Todo::REST::API version 0.0.1
155:
156:
157: =head1 SYNOPSIS
158:
159: use Text::Todo::REST::API;
160:
161: =for author to fill in:
162: Brief code example(s) here showing commonest usage(s).
163: This section will be as far as many users bother reading
164: so make it as educational and exeplary as possible.
165:
166:
167: =head1 DESCRIPTION
168:
169: =for author to fill in:
170: Write a full description of the module and its features here.
171: Use subsections (=head2, =head3) as appropriate.
172:
173:
174: =head1 INTERFACE
175:
176: =for author to fill in:
177: Write a separate section listing the public components of the modules
178: interface. These normally consist of either subroutines that may be
179: exported, or methods that may be called on objects belonging to the
180: classes provided by the module.
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::REST::API 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-rest-api@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) 2010, 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>