Hello wise monks,
I am preparing to post on CPAN some modules that I have written in order to run CGI::Application apps as FastCGI "singleton" classes.
I suppose I need to explain a little. CGI::App is perfectly suitable for writing applications that run once. For example, when run in CGI or in mod_perl envoronment the usual behaviour is to instantiate the web class for every request and discard it after that. You could do the same in FastCGI environment but I have tried to make a singleton web-application class that only resets the CGI parameters on every request and reuses the same class instance. In this way I could have a heavy init phase (some constant stuff from DB) that do not affect the processing time for every request. I have found that CGI::App core is perfectly suitable for the task but there are some plugins that do not play well. So I have decided to write some drop in replacement for this modules. For example, CGI::Application::Singleton::Session is drop-in replacement for CGI::Application::Plugin::Session and CGI::Application::Singleton::Redirect is replacement for CGI::Application::Plugin::Redirect.
The problem also arised in Authentication and Authorization plugins. But I was unhappy with its API and decided to make a try on the problem. I wanted to have some declarative framework, so I opted for sub attrubutes. En example worths thousand words, so here its is:
#!/usr/bin/perl package webapp::item use webapp qw(role method); use base 'webapp'; # everybody sees it sub show :StartRunMode { ... } # Authenticated users only sub post_comment :RunMode :Protected { ... } # Authenticated & authorized - only admin or moderator # could delete items sub delete :RunMode :Protected(role('admin'), role('moderator')) { ... } # Only authenticated and throught POST http method sub save :RunMode :Protected(method('POST')) { ... }
The code in the module is short but I have added a lot of documentation in it with full example. You could get it http://luben.unixsol.org/Protect.pm. It cooperates with sessions management plugin and a dispatcher that I am refactoring now. The relevant code from the dispatcher is this:
So, here are my hesitations and questions:sub cgiapp_dispatch { my $self = shift; my $mode = $self->parse_path_info(); return $self->cgiapp_protect ($mode) if $self->can('cgiapp_protect'); return $mode; }
Thanks in advance
luben
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::App declarative authentication and authorization
by Anonymous Monk on Jan 23, 2009 at 15:55 UTC | |
by Lawliet (Curate) on Jan 23, 2009 at 17:56 UTC | |
by karavelov (Monk) on Jan 24, 2009 at 21:29 UTC |