=================================================================== RCS file: /cvs/todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/23 07:15:40 1.9 +++ todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/24 04:17:39 1.10 @@ -1,12 +1,13 @@ 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 strict; use Carp; use Text::Todo; +use Text::Todo::REST::API::Response; use Class::Std::Utils; use Digest::MD5 qw/ md5_hex /; @@ -94,16 +95,17 @@ } } - if ($options{action} eq 'entry' && @{ $options{args} }) { + if ( $options{action} eq 'entry' && @{ $options{args} } ) { $options{entry} = shift @{ $options{args} }; - if (@{ $options{args} }) { + if ( @{ $options{args} } ) { $options{action} = lc shift @{ $options{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} ) { $format_of{ ident $self } = $options{format}; @@ -124,14 +126,20 @@ sub _handle_action { my ( $self, @args ) = @_; - my ($method, %options) = $self->_parse_options(@args); + my ( $method, %options ) = $self->_parse_options(@args); my $todo = $self->_todo; $todo->load( $options{list} ); - foreach my $class ( $self ) { - if ($class->can($method) ) { - return $class->$method( $todo, \%options ); + foreach my $class ($self) { + if ( $class->can($method) ) { + my @data = $class->$method( $todo, \%options ); + + return Text::Todo::REST::API::Response->new({ + type => $options{action}, + format => $self->_format, + data => \@data, + }); } } @@ -162,12 +170,12 @@ my $suffix = $self->_suffix; - if (( lc $options{list} ) eq 'files') { + if ( ( lc $options{list} ) eq 'files' ) { $options{action} = lc $options{list}; - $options{list} = q{}; + $options{list} = q{}; } - elsif ($self->_todo->file( $options{list} )) { - $options{list} = $self->_todo->file( $options{list} ); + elsif ( $self->_todo->file( $options{list} ) ) { + $options{list} = $self->_todo->file( $options{list} ); } } @@ -197,8 +205,8 @@ return @entries; } elsif ( ref $key eq 'HASH' ) { - if (exists $key->{entry}) { - $key = $key->{entry}; + if ( exists $key->{entry} ) { + $key = $key->{entry}; } else { return $self->fail('get_entry requires key [entry]'); @@ -230,7 +238,7 @@ } sub get_list { - my ($self, $todo) = @_; + my ( $self, $todo ) = @_; my $line = 1; return map ( { @@ -242,7 +250,7 @@ } sub get_files { - my ($self, $todo) = @_; + my ( $self, $todo ) = @_; my $dir = $todo->file('todo_dir'); if ( !$dir ) {