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:

sub cgiapp_dispatch { my $self = shift; my $mode = $self->parse_path_info(); return $self->cgiapp_protect ($mode) if $self->can('cgiapp_protect'); return $mode; }
So, here are my hesitations and questions:
  1. Regarding CGI::Application structure: is this the right way to extend it?
  2. Redarding the A&A API: Does that make sense to you and did you find this useful? One of my motivation points was that I wanted to declare the security context on the same place as the code
  3. This will be my fist CPAN submission. So, is there enought and helpfull documentation? Do I miss something?
  4. And last but not least, I am open to all kinds of suggestions and critics concerning the code

Thanks in advance

luben

In reply to CGI::App declarative authentication and authorization by karavelov

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.