[cgiapp] authentication and authorization callbacks

Mark Stosberg mark at summersault.com
Tue Nov 6 15:32:13 EST 2012


> You call init in BUILD, but then explicitly run down the callback list in 
> the run() method. What I am wondering is if you could bridge the gap to the 
> other side that would allow one to munge around with the *ordered contents 
> of %CLASS_CALLBACKS.
> 
> my %CLASS_CALLBACKS = (
> #   hook name          package                 sub
>     init      => { 'PSGI::Application' => [ 'init'    ] },
>     prerun    => { 'PSGI::Application' => [ 'prerun'  ] },
>     
> # for example, add
>     authentication  => { 'My::PSGI::Application' => [ 'authentication'  ] },
>     authorization   => { 'My::PSGI::Application' => [ 'authorization'  ] },
> 
>     postrun   => { 'PSGI::Application' => [ 'postrun' ] },
>     teardown  => { 'PSGI::Application' => [ 'teardown'] },
>     load_tmpl => { },
>     error     => { },
> );
> 
> Instead of me having to reimplement the run() method to provide for custom
> top level callbacks, would it be possible to craft run() so that it took
> %CLASS_CALLBACKS as ordered (e.g., if %CLASS_CALLBACKS was tied with 
> Tie::Hash::Indexed) ?
> 
> Right now, it seems like I'd have to reimplement the run(), when all I really wanted
> to do was insert top level callback classes wrt the order in which they are run.

Brett, I think this existing functionality would provide what you want:

 PSGI::Application->new_hook('authorization');
 PSGI::Application->add_callback('authorization', \&callback);

That would register a hook named 'authorization', and register a
callback to fire the same as it would as if it were in the built-in hash.

Or have I misunderstood the request?

If need-be, we could make %CLASS_CALLBACKS, replaceable, but I want to
be first be clear that there's a need.

   Mark


More information about the cgiapp mailing list