[BACK]Return to GET.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/GET.pm, Revision 1.2

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

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