=================================================================== RCS file: /cvs/todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/18 03:51:40 1.6 +++ todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/18 13:47:53 1.7 @@ -1,6 +1,6 @@ package Text::Todo::REST::API; -# $AFresh1: API.pm,v 1.5 2010/01/18 03:10:42 andrew Exp $ +# $AFresh1: API.pm,v 1.6 2010/01/18 03:51:40 andrew Exp $ use warnings; use strict; @@ -15,7 +15,6 @@ search_path => __PACKAGE__ . '::Representations', sub_name => 'representations'; use Digest::MD5 qw/ md5_hex /; -use File::Spec; use version; our $VERSION = qv('0.0.1'); @@ -31,9 +30,6 @@ my @attr_refs = \( my %todo_of, - my %basedir_of, - my %subdir_of, - my %suffix_of, my %file_regex_of, @@ -75,8 +71,6 @@ } } - $basedir_of{$ident} = $options->{basedir}; - $subdir_of{$ident} = $options->{subdir}; $suffix_of{$ident} = $options->{suffix} || '.txt'; $file_regex_of{$ident} = $options->{file_regex} || qr{ @@ -87,48 +81,29 @@ $ }ixms; - if ( !$basedir_of{$ident} ) { - return $self->fail('Required option [basedir]'); - } - $options->{path_info} ||= q{}; $options->{path_info} =~ s{^/}{}xms; - ( $user_of{$ident}, $list_of{$ident}, - $action_of{$ident}, @{ $args_of{$ident} }, + ( $list_of{$ident}, $action_of{$ident}, @{ $args_of{$ident} }, ) = split '/', $options->{path_info}; if ( $list_of{$ident} ) { $action_of{$ident} ||= 'list'; } - elsif ( $user_of{$ident} ) { + else { $action_of{$ident} = 'files'; } - my @todo_dir = $basedir_of{$ident}; - - my $todo_dir; - if ( $user_of{$ident} ) { - push @todo_dir, $user_of{$ident}; - if ( $subdir_of{$ident} ) { - push @todo_dir, $subdir_of{$ident}; + eval { $todo_of{$ident} = Text::Todo->new( + { todo_dir => $options->{todo_dir}, + todo_file => $options->{todo_file}, } - - $todo_dir = File::Spec->catdir(@todo_dir); + ) }; + if ($@) { + $self->fail('Unable to create Text::Todo object' . $@); } - my $todo_file; - if ( $list_of{$ident} ) { - $todo_file = $list_of{$ident} . $suffix_of{$ident}; - } - - $todo_of{$ident} = Text::Todo->new( - { todo_dir => $todo_dir, - todo_file => $todo_file, - } - ) or $self->fail('Unable to create Text::Todo object'); - $todo_of{$ident}->load('todo_file') - or $self->fail('Unable to create Text::Todo object'); + or $self->fail('Unable to load todo_file in Text::Todo object'); return $self; } @@ -267,8 +242,6 @@ } sub _todo { my ($self) = @_; return $todo_of{ ident $self }; } - sub _basedir { my ($self) = @_; return $basedir_of{ ident $self}; } - sub _subdir { my ($self) = @_; return $subdir_of{ ident $self}; } sub _suffix { my ($self) = @_; return $suffix_of{ ident $self}; } sub _file_regex { my ($self) = @_; return $file_regex_of{ ident $self}; } sub _user { my ($self) = @_; return $user_of{ ident $self}; }