version 1.18, 2010/02/13 21:48:28 |
version 1.19, 2010/02/16 06:12:26 |
|
|
package Text::Todo::REST::API; |
package Text::Todo::REST::API; |
|
|
# $AFresh1: API.pm,v 1.17 2010/01/31 03:10:39 andrew Exp $ |
# $AFresh1: API.pm,v 1.18 2010/02/13 21:48:28 andrew Exp $ |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
|
|
} |
} |
|
|
sub _parse_options { |
sub _parse_options { |
my ( $self, $method, @args ) = @_; |
my ( $self, $method, @options) = @_; |
|
|
my %options = ( |
my %options = ( |
method => lc $method, |
method => lc $method, |
list => '', |
list => '', |
action => 'files', |
action => 'files', |
args => [], |
args => {}, |
|
|
suffix => $self->_suffix, |
suffix => $self->_suffix, |
file_regex => $self->_file_regex, |
file_regex => $self->_file_regex, |
format => $self->_format, |
format => $self->_format, |
); |
); |
|
|
if (@args) { |
if (@options) { |
if ( !ref $args[0] ) { |
if ( !ref $options[0] ) { |
$options{path} = shift @args; |
$options{path} = shift @options; |
} |
} |
|
|
if ( ref $args[0] eq 'HASH' ) { |
if ( ref $options[0] eq 'HASH' ) { |
my $opts = shift @args; |
my $opts = shift @options; |
foreach my $o ( keys %{$opts} ) { |
foreach my $o ( keys %{$opts} ) { |
$options{$o} = $opts->{$o}; |
$options{$o} = $opts->{$o}; |
} |
} |
|
|
} |
} |
} |
} |
|
|
if ( $options{action} eq 'entry' && @{ $options{args} } ) { |
if ( $options{action} eq 'entry' && @{ $options{extra} } ) { |
$options{action} .= q{_} . lc shift @{ $options{args} }; |
$options{action} .= q{_} . lc shift @{ $options{extra} }; |
} |
} |
|
|
|
push @{ $options{extra} }, @options; |
|
|
push @{ $options{args} }, @args; |
|
|
|
my $list = $self->_todo->file( $options{list} ); |
my $list = $self->_todo->file( $options{list} ); |
|
|
my $suffix = $self->_suffix || q{}; |
my $suffix = $self->_suffix || q{}; |
|
|
action => undef, |
action => undef, |
list => undef, |
list => undef, |
entry => undef, |
entry => undef, |
args => [], |
extra => [], |
); |
); |
|
|
$path = defined $path ? $path : q{}; |
$path = defined $path ? $path : q{}; |
|
|
} |
} |
|
|
( $options{list}, $options{action}, |
( $options{list}, $options{action}, |
@{ $options{args} } ) = split '/', $path; |
@{ $options{extra} } ) = split '/', $path; |
|
|
if (!defined $options{action}) { |
if (!defined $options{action}) { |
if ( $options{list} ) { |
if ( $options{list} ) { |
|
|
if ($options{action} eq 'entry' |
if ($options{action} eq 'entry' |
|| $options{action} eq 'tags' |
|| $options{action} eq 'tags' |
) { |
) { |
$options{ $options{action} } = shift @{ $options{args} }; |
$options{ $options{action} } = shift @{ $options{extra} }; |
} |
} |
|
|
return %options; |
return %options; |