[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] RFC: CAP::Plugin::PathInfo


Hi all,

With many cool CAP Plugins being produced recently, and all the REST
discussion, I decided to try my hand at writing a Plugin of my
own. It's embarrassingly simple, but maybe someone will find it
useful.

It sets a pre_run callback that takes path info and inserts it into
the CGI (or CGI::Simple) query object. In setup() you can pass in
names for the expected params for each run mode. By default it will
set param names like "path_info_1", "path_info_2", etc. if the param
names aren't set.

I'd like to say that it can help in creating RESTful web apps, but
after seeing Timothy Appnel's recent post regarding REST, I think I
should do some reading before making that claim.

If anyone has any opinions or ideas on how to make this more RESTful,
more full of any other buzzy acronym, or just more BETTERful, please
let me know.

The rough, slightly tested code is at:
http://www.skiddlydee.com/stuff/PathInfo.pm


Here's the beginnings of some POD:

=head1 NAME

CGI::Application::Plugin::PathInfo - convert path data into query parameters

=head1 SYNOPSIS

 use CGI::Application::Plugin::PathInfo

 # In setup()
 sub setup {
   my $self = shift;
   $self->start_mode('list');
   $self->run_modes(
		    'edit' => 'showform',
		    'list' => 'showlist',
		    'products' => 'showdetail'
		   );
	
   # set param names for the elements of path info
   $self->param('path_info_vars'=>
		{
		 'showdetail'=>['rm','category_id','item_id','color'],
		 'showform'=>['rm','item_id'],
		 'showlist'=>0, #ignore any path info (besides runmode)
		}
	       );
   }

# This URL:
# http://www.myapp.com/products/jam/1999/purple
#
# would result in the following params added to $self->query

   'rm' => 'products',
   'category' =>'jam',
   'item_id' =>'1999',
   'color' =>'purple'


=head1 DESCRIPTION

CGI::Application::Plugin::PathInfo adds a pre_run callback to
CGI::Application which will automatically take data from the PATH_INFO
and put it into CGI query object.

The parameter names for the expected path info elements can be set in
the setup() method. If not set, they'll be set to "path_info_1",
"path_info_2", etc. by default. You prevent path info from being added
to the query obj for a given runmode by setting the value to 0, like
this:

  $self->param('path_info_vars'=>
             {
	      'showlist'=>0, #don't want no stinkin' path info
              }
	      );



An advantage of having the data from path info added to the query is
that it makes it easy to validate it using, for example,
CAP::Plugin::ValidateRM

=head1 METHODS

Just path_info_to_query, which is not exported


=head1 DEPENDENCIES

Requires CGI::Application version >= 4.01
(uses the new call-back functionality)

=cut


Regards,
David Emery
suppressed




---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.