=================================================================== RCS file: /cvs/todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/18 03:10:42 1.5 +++ todotxt/Text-Todo-REST-API/lib/Text/Todo/REST/API.pm 2010/01/18 03:51:40 1.6 @@ -1,6 +1,6 @@ package Text::Todo::REST::API; -# $AFresh1: API.pm,v 1.4 2010/01/18 00:30:42 andrew Exp $ +# $AFresh1: API.pm,v 1.5 2010/01/18 03:10:42 andrew Exp $ use warnings; use strict; @@ -10,6 +10,10 @@ use Text::Todo; use Class::Std::Utils; +use Module::Pluggable + require => 1, + search_path => __PACKAGE__ . '::Representations', + sub_name => 'representations'; use Digest::MD5 qw/ md5_hex /; use File::Spec; @@ -26,24 +30,24 @@ { 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 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}; @@ -54,11 +58,19 @@ $format = $1; } + my $self = bless anon_scalar(), $class; + my $ident = ident($self); + if ( ref $self eq __PACKAGE__ && $format ) { - if ( $format_handlers{$format} ) { - bless $self, $format_handlers{$format}; + my $found_handler = 0; + REP: foreach my $rep ( $self->representations ) { + if ( $rep->_handles($format) ) { + $self = $rep->new($options); + $found_handler = 1; + last REP; + } } - else { + if ( !$found_handler ) { croak("Unable to find handler for [$format]\n"); } } @@ -119,16 +131,6 @@ or $self->fail('Unable to create Text::Todo object'); return $self; - } - - sub RegisterFormatHandler { - my ( $handler, @types ) = @_; - - foreach my $type (@types) { - $format_handlers{$type} = $handler; - } - - return 1; } sub RegisterActionHandler {