On 2005-07-05, Michael Peters <[EMAIL PROTECTED]> wrote:
>>>Second, If I don't implement a setup method then the 'start_mode' get's
>>>set twice. Once in new() (line 43) and then once again in the default
>>>setup(). Do we really need this? It just seems redundant and actually
>>>clobbers any attempt to set a start_mode on my own in my callback at
>>>init. The only way I can get around it is to define an empty setup()
>>>method. Thoughts?
>>
>>
>> Could this be addressed by patching C::A so these calls:
>>
>> $self->start_mode('start');
>>
>> Become:
>>
>> $self->start_mode('start') unless defined $self->start_mode();
>
> Yeah, that's one way of doing it. The other would be to just remove the
> line $self->start_mode('start') in setup() since it's completely
> redundant anyway. But I would still change the line in new() to do as
> you have proposed just incase someone choose to set it in an init
> callback (like I did :)
I agree it should be safe to remove that line from setup(), since not
only is it redundant, but people nearly universally override setup() and
will thus be unaffected by the change.
I suspect it existed in the source code more as an example.
OK, I just whipped up this related patch. It goes a little further and
moves the setting of defaults in new() until after the init hook, giving
the hook a chance to set 'start_mode' before the application default is
established. None of the test suite failed. :)
You could enhance the patch further by writing a test that confirms the change
plays well with the hook system. If it does, that might quell some of the need
for a setup() hook.
( This change is also in my published darcs repo.)
Mark
diff -rN -u old-dist/lib/CGI/Application.pm new-dist/lib/CGI/Application.pm
--- old-dist/lib/CGI/Application.pm 2005-06-14 09:33:09.000000000 -0500
+++ new-dist/lib/CGI/Application.pm 2005-07-05 10:21:17.000000000 -0500
@@ -33,16 +33,6 @@
my $self = {};
bless($self, $class);
- ### SET UP DEFAULT VALUES ###
- #
- # We set them up here and not in the setup() because a subclass
- # which implements setup() still needs default values!
-
- $self->header_type('header');
- $self->mode_param('rm');
- $self->start_mode('start');
-
-
# Process optional new() parameters
my $rprops;
if (ref($args[0]) eq 'HASH') {
@@ -79,6 +69,15 @@
# down the line.
$self->call_hook('init', @args);
+ ### SET UP DEFAULT VALUES ###
+ #
+ # We set them up here and not in the setup() because a subclass
+ # which implements setup() still needs default values!
+
+ $self->header_type('header');
+ $self->mode_param('rm');
+ $self->start_mode('start') unless defined $self->start_mode;
+
# Call setup() method, which should be implemented in the sub-class!
$self->setup();
@@ -236,7 +235,6 @@
sub setup {
my $self = shift;
- $self->start_mode('start');
$self->run_modes(
'start' => 'dump_html',
);
---------------------------------------------------------------------
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]