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

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

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