[cgiapp] Re: order of operations

P Kishor punk.kish at gmail.com
Wed Aug 12 13:07:18 EDT 2009


Replying to my own email to clarify one point that was not obvious to me --

On Wed, Aug 12, 2009 at 10:27 AM, P Kishor<punk.kish at gmail.com> wrote:
> I have read the article on "Order of Operations" at
> http://cgiapp.erlbaum.net/index.cgi?OrderOfOperations but I am not
> clear as to what is going on in my situation. Here is what I have
>
> --- MyAuthen.pm ---
> package MyAuthen;
>
> 1. sub cgiapp_get_query { .. }
> 2. sub cgiapp_init { .. }
>
> 3. sub setup {
> ..
>    $self->run_modes([qw(welcome login other_run_modes)]);
>    $self->start_mode('welcome');
>    $self->param(protected_runmodes => [qw(other_run_modes)]);
> }
>
> 4. sub cgiapp_prerun {
>    my $self = shift;
>
>    my $protected_runmodes = $self->param('protected_runmodes');
>    foreach my $rm (@$protected_runmodes) {
>        if ($self->prerun_mode() eq $rm) {
>            unless ($self->session->param('is_logged_in')) {
>                $self->prerun_mode('login');
>            }
>            last;
>        }
>    }
> }
>
> 5. sub welcome { .. }
> 6. sub login { .. }
> 7. sub other_run_modes { .. }
> ====
>
> --- MyApp.pm ---
> package MyApp;
>
> use strict;
> use base 'MyAuthen';
>
> 1. sub setup {
>    my $self = shift;
>    $self->SUPER::setup();
>    $self->run_modes([qw( welcome view )]);
>    $self->start_mode('welcome');
>    $self->param(protected_runmodes => [qw(view)]);


The above line re-declares the protected_runmodes param, so all the
protected_runmodes set in MyAuthen vanish and we left with only 'view'
as a protected_runmode. The following code corrects the situation

my $protected_runmodes = $self->param('protected_runmodes');
push @$protected_runmodes, 'view';


> }
>
> 2. sub welcome { .. }
> 3. sub view { .. }
> ====
>
> Ok. This is what I expect to happen when I call MyApp::view (http://<site>/view)
>
> MyAuthen.1 cgiapp_get_query()
> MyAuthen.2 cgiapp_init()
> MyApp.1    setup()
>  -- MyAuthen3. setup() called by $self->SUPER::setup()
>  -- rest of MyApp.1 setup()
>
> By this time, I expect the following
>
> run_modes = qw( -welcome- login other_run_modes) + qw( welcome view )
>
> in other words, run_modes from MyApp will be added to the list of
> run_modes from MyAuthen, and MyApp's welcome() will override
> MyAuthen's welcome.
>
> protected_runmodes = qw( other_run_modes view )
>
> MyAuthen.4 cgiapp_prerun()
> MyAuthen.6 login()
> MyApp.3    view() assuming login in succeeded.
>
> Remark: When I request view as above, it gets called directly without
> any of the nonsense listed above happening, implying that either it
> was not regarded as one of the protected_runmodes or that MyAuthen.4
> cgiapp_prerun() didn't kick in, or both.
>
> Is my assumption of the order of operations correct? What am I doing
> wrong? What can I do better?
>
>
> --
> Puneet Kishor http://www.punkish.org
> Carbon Model http://carbonmodel.org
> Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
> Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
> Nelson Institute, UW-Madison http://www.nelson.wisc.edu
> -----------------------------------------------------------------------
> Assertions are politics; backing up assertions with evidence is science
> =======================================================================
> Sent from Madison, WI, United States
>


More information about the cgiapp mailing list