order of operations

View: New views
5 Messages — Rating Filter:   Alert me  

order of operations

by P Kishor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: order of operations

by Mark Fuller-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Aug 12, 2009 at 8:27 AM, P Kishor<punk.kish@...> wrote:
> I have read the article on "Order of Operations" at
> http://cgiapp.erlbaum.net/index.cgi?OrderOfOperations ...

I can't answer your question. But, I never saw that document before.
It's really useful.

I think it would be beneficial if the POD had a section "Order of
operations" (maybe after "More application methods") and linked to
that document.

Mark

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: order of operations

by P Kishor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...> 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
>

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: Re: order of operations

by Ron Savage :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Puneet

On Wed, 2009-08-12 at 12:07 -0500, P Kishor wrote:

> > 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';

All that does is store the run modes in an array local to the sub.

It does /not/ pass the updated list back to whatever object manages
these things.

--
Ron Savage
ron@...
http://savage.net.au/index.html



#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: Re: order of operations

by P Kishor-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Aug 12, 2009 at 5:50 PM, Ron Savage<ron@...> wrote:

> Hi Puneet
>
> On Wed, 2009-08-12 at 12:07 -0500, P Kishor wrote:
>> > 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';
>
> All that does is store the run modes in an array local to the sub.
>
> It does /not/ pass the updated list back to whatever object manages
> these things.
>

correct... that is because in my excitement I posted only half the
code. I do the following

in the base class

sub setup {
  $self->_protected_runmodes([qw(r1 r2 r3)]);
}

and nearby

sub _protected_runmodes {
    my $self = shift;
    my $runmodes = shift;

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

then, in inherited class I can do

sub setup {
  my $self = shift;
  $self->SUPER::setup();
  $self->_protected_runmodes([qw(r4)]);
}

and I get r4 added to the list of protected runmodes.

It all works, at least for now.





--
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

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################