[cgiapp] order of operations

P Kishor punk.kish at gmail.com
Wed Aug 12 11:27:19 EDT 2009


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)]);
}

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