[BACK]Return to PUT.pm CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo-REST-API / lib / Text / Todo / REST / API / Actions

Annotation of todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API/Actions/PUT.pm, Revision 1.3

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

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