=================================================================== RCS file: /cvs/todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/18 00:30:42 1.4 +++ todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/18 03:10:42 1.5 @@ -1,6 +1,6 @@ package Text::Todo::REST::API; -# $AFresh1: API.pm,v 1.3 2010/01/17 23:48:06 andrew Exp $ +# $AFresh1: API.pm,v 1.4 2010/01/18 00:30:42 andrew Exp $ use warnings; use strict; @@ -9,7 +9,7 @@ use Data::Dumper; use Text::Todo; -use Class::Std; +use Class::Std::Utils; use Digest::MD5 qw/ md5_hex /; use File::Spec; @@ -24,15 +24,26 @@ ); { - my (%todo_of, %basedir_of, %subdir_of, - %suffix_of, %file_regex_of, %user_of, - %list_of, %action_of, %args_of, - %action_handlers, %format_handlers, - ) : ATTRS; + my @attr_refs = \( + my %todo_of, + my %basedir_of, + my %subdir_of, + my %suffix_of, + my %file_regex_of, + my %user_of, + my %list_of, + my %action_of, + my %args_of, + my %action_handlers, + my %format_handlers, + ); - sub BUILD { - my ( $self, $ident, $options ) = @_; + sub new { + my ( $class, $options ) = @_; + my $self = bless anon_scalar(), $class; + my $ident = ident($self); + my $format = $options->{default_format}; if ( $options->{format} ) { $format = $options->{format}; @@ -107,7 +118,7 @@ $todo_of{$ident}->load('todo_file') or $self->fail('Unable to create Text::Todo object'); - return; + return $self; } sub RegisterFormatHandler { @@ -130,7 +141,7 @@ return 1; } - sub content_type { return }; + sub content_type {return} sub Dump { my ($self) = @_; @@ -233,12 +244,12 @@ return $todo_of{$ident}->listtag($tag); } - sub POST { + sub POST { my ( $self, @args ) = @_; return $self->_handle_action( 'POST', @args ); } - sub PUT { + sub PUT { my ( $self, @args ) = @_; return $self->_handle_action( 'PUT', @args ); } @@ -263,6 +274,13 @@ sub _action { my ($self) = @_; return $action_of{ ident $self}; } sub _args { my ($self) = @_; return $args_of{ ident $self}; } + sub DESTROY { + my ($self) = @_; + my $ident = ident $self; + foreach my $attr_ref (@attr_refs) { + delete $attr_ref->{$ident}; + } + } } 1; # Magic true value required at end of module __END__