I hate to write (ok it's a macro - but still) even the my $self = shift; part in each runmode - and you have the check in each one?

I've came up with this before Authen plugin was written ...

== this is the "base module shared by all - I use base *it* instead of + CGI::App directly. package YPTP::App; use strict; use base 'CGI::Application'; use base 'YPTP::DataBase'; use base 'YPTP::Email'; use CGI::Application::Plugin::TT; # TemplateToolkit use CGI::Application::Plugin::Session; # CGI::Session use CGI::Application::Plugin::AutoRunmode; sub cgiapp_init { my $self = shift; .... ussual setup stuff ... } # In case most of pages are public - if not I set it to return 0 sub authorize { my $self = shift; return 1; } sub cgiapp_prerun { my ($self, $run_mode) = @_; # CGI::APP doesn't alow you to change runmode at init stage - say +if there is an error with # DB connection ... So I set it there and catch it here. if( $self->param('error') ){ $self->prerun_mode('ERROR'); } # Maybe only some runmodes need to be protected - so we send the r +unmode name to decide unless( $self->authorize($run_mode) ){ # Error $self->prerun_mode('NOT_AUTHORIZED'); } } === some module containing runmodes connected logically package YPTP::Runmodes::Admin; use strict; use base 'YPTP::App'; sub authorize { my $self = shift; my $runmode = shift; my $type = $self->session->param('type'); return 1 if($type eq 'admin'); # admin can do anything return 0; # everyone else can't do a thing }
I'm obviously using CGI::Application::Dispatch to decide which file/module to call. So for each file containing runmodes you can override the default authorize method and even check auth based on runmode to be called.
sub authorize { my $self = shift; my $runmode = shift; my $tip = $self->session->param('tip'); return 1 if($tip eq 'admin'); # Admin moze sve ! :) my $auth = { 'index' => 1, # everyone profil_forma => $tip eq 'poslodavac', profil_obrada => $tip eq 'poslodavac', '_default' => $tip eq 'poslodavac' }; if(defined $auth->{$runmode}) { return $auth->{$runmode}; } else { return $auth->{_default}; } }

Have you tried freelancing? Check out Scriptlance - I work there. For more info about Scriptlance and freelancing in general check out my home node.

In reply to Re^2: CGI::Application::Authentication and Static Pages by techcode
in thread CGI::Application::Authentication and Static Pages by digger

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.