version 1.9, 2010/01/23 07:15:40 |
version 1.10, 2010/01/24 04:17:39 |
|
|
package Text::Todo::REST::API; |
package Text::Todo::REST::API; |
|
|
# $AFresh1: API.pm,v 1.8 2010/01/19 03:18:34 andrew Exp $ |
# $AFresh1: API.pm,v 1.9 2010/01/23 07:15:40 andrew Exp $ |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
use Carp; |
use Carp; |
|
|
use Text::Todo; |
use Text::Todo; |
|
use Text::Todo::REST::API::Response; |
|
|
use Class::Std::Utils; |
use Class::Std::Utils; |
use Digest::MD5 qw/ md5_hex /; |
use Digest::MD5 qw/ md5_hex /; |
|
|
} |
} |
} |
} |
|
|
if ($options{action} eq 'entry' && @{ $options{args} }) { |
if ( $options{action} eq 'entry' && @{ $options{args} } ) { |
$options{entry} = shift @{ $options{args} }; |
$options{entry} = shift @{ $options{args} }; |
if (@{ $options{args} }) { |
if ( @{ $options{args} } ) { |
$options{action} = lc shift @{ $options{args} }; |
$options{action} = lc shift @{ $options{args} }; |
} |
} |
} |
} |
|
|
push @{ $options{args} }, @args; |
push @{ $options{args} }, @args; |
|
|
$options{list} = defined $options{list} ? $options{list} : 'todo_file'; |
$options{list} |
|
= defined $options{list} ? $options{list} : 'todo_file'; |
|
|
if ( $options{format} ) { |
if ( $options{format} ) { |
$format_of{ ident $self } = $options{format}; |
$format_of{ ident $self } = $options{format}; |
|
|
sub _handle_action { |
sub _handle_action { |
my ( $self, @args ) = @_; |
my ( $self, @args ) = @_; |
|
|
my ($method, %options) = $self->_parse_options(@args); |
my ( $method, %options ) = $self->_parse_options(@args); |
|
|
my $todo = $self->_todo; |
my $todo = $self->_todo; |
$todo->load( $options{list} ); |
$todo->load( $options{list} ); |
|
|
foreach my $class ( $self ) { |
foreach my $class ($self) { |
if ($class->can($method) ) { |
if ( $class->can($method) ) { |
return $class->$method( $todo, \%options ); |
my @data = $class->$method( $todo, \%options ); |
|
|
|
return Text::Todo::REST::API::Response->new({ |
|
type => $options{action}, |
|
format => $self->_format, |
|
data => \@data, |
|
}); |
} |
} |
} |
} |
|
|
|
|
|
|
my $suffix = $self->_suffix; |
my $suffix = $self->_suffix; |
|
|
if (( lc $options{list} ) eq 'files') { |
if ( ( lc $options{list} ) eq 'files' ) { |
$options{action} = lc $options{list}; |
$options{action} = lc $options{list}; |
$options{list} = q{}; |
$options{list} = q{}; |
} |
} |
elsif ($self->_todo->file( $options{list} )) { |
elsif ( $self->_todo->file( $options{list} ) ) { |
$options{list} = $self->_todo->file( $options{list} ); |
$options{list} = $self->_todo->file( $options{list} ); |
} |
} |
} |
} |
|
|
|
|
return @entries; |
return @entries; |
} |
} |
elsif ( ref $key eq 'HASH' ) { |
elsif ( ref $key eq 'HASH' ) { |
if (exists $key->{entry}) { |
if ( exists $key->{entry} ) { |
$key = $key->{entry}; |
$key = $key->{entry}; |
} |
} |
else { |
else { |
return $self->fail('get_entry requires key [entry]'); |
return $self->fail('get_entry requires key [entry]'); |
|
|
} |
} |
|
|
sub get_list { |
sub get_list { |
my ($self, $todo) = @_; |
my ( $self, $todo ) = @_; |
|
|
my $line = 1; |
my $line = 1; |
return map ( { |
return map ( { |
|
|
} |
} |
|
|
sub get_files { |
sub get_files { |
my ($self, $todo) = @_; |
my ( $self, $todo ) = @_; |
my $dir = $todo->file('todo_dir'); |
my $dir = $todo->file('todo_dir'); |
|
|
if ( !$dir ) { |
if ( !$dir ) { |