On 12/14/05, Michael Graham <[EMAIL PROTECTED]> wrote:
>
> On Tue, 13 Dec 2005 09:17:18 -0500
> Rob Kinyon <[EMAIL PROTECTED]> wrote:
> > Well, it currently happens in the run() method in CGI/Application.pm.
> > I don't see any reason why the proposed steps-to-run would require any
> > change other than where the code the fulfills that step lives.
>
> But how would dispatch to a different module work? E.g.
>
> my $app = My::Base::Class->new;
> $app->dispatch(
> TABLE => [
> 'blog' => { app => 'Blog' }
> ]
> );
>
> Assuming that 'Blog' is a subclass of 'My::Base::Class', how can $app
> (which ISA 'My::Base::Class') dispatch to one of its own subclasses?
> Would it create (and run) a new instance of $app? Or would it rebless
> itself into the new package?
I'm not sure how this relates to what Rob was talking about in the
comment above, but I'll try to explain what I think Rob is actually
talking about regarding the current implementation of the 'run' method
in CGI::Application.
the 'run' method is over 100 lines long when we include whitespace and
comments. 62 lines of actual perl code. That is a pretty big
subroutine, and it is core to the way CGI::Application works. If
someone (like a plugin author) wants to make a slight change to the
way things work in the 'run' method, you have to copy the entire thing
into a subclass just to make a small little change.
Rob is suggesting we refactor this one 'run' method into several
smaller methods, which will make it easier to make slight changes to
the process and also clarify the code. I'll give an example of
something that could be refactored in the 'run' method. Look at this
code here (it is the first thing thatis done in the 'run' method):
my $rm_param = $self->mode_param() || croak("No rm_param() specified");
my $rm;
# Support call-back instead of CGI mode param
if (ref($rm_param) eq 'CODE') {
# Get run mode from subref
$rm = $rm_param->($self);
}
# support setting run mode from PATH_INFO
elsif (ref($rm_param) eq 'HASH') {
$rm = $rm_param->{run_mode};
}
# Get run mode from CGI param
else {
$rm = $q->param($rm_param);
}
We could rewrite that like this:
my $rm = $self->get_the runmode_for_the_current_request();
sub get_the runmode_for_the_current_request {
my $self = shift;
my $rm_param = $self->mode_param() || croak("No rm_param() specified");
my $rm;
# Support call-back instead of CGI mode param
if (ref($rm_param) eq 'CODE') {
# Get run mode from subref
$rm = $rm_param->($self);
}
# support setting run mode from PATH_INFO
elsif (ref($rm_param) eq 'HASH') {
$rm = $rm_param->{run_mode};
}
# Get run mode from CGI param
else {
$rm = $q->param($rm_param);
}
return $rm;
}
So no functionality has changed, but the 'run' method is a little bit
shorter and clearer, and we now have a way of altering the way the
runmode is chosen by overriding that method. That might be useful to
something like the AutoRunmode plugin.
So I don't think Rob is talking about changing the whole philosophy of
CGI::Application, he is just talking about refactoring some bloated
methods into smaller pieces (which is generally considered a good
thing).
Cheers,
Cees
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]