can AUTOLOAD sub be named AUTOLOAD?

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

can AUTOLOAD sub be named AUTOLOAD?

by rjmorris12 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

When creating an AUTOLOAD run mode, I wanted to name the method AUTOLOAD, so
I set up my application module as:


sub setup {
  my ($self) = @_;
  $self->run_modes([qw/mode1 mode2 AUTOLOAD/]);
  $self->start_mode("mode1");
}
 
sub mode1 { return "running mode1\n"; }
sub mode2 { return "running mode2\n"; }
sub AUTOLOAD {
  my ($self, $requested_mode) = @_;
  print STDERR "running AUTOLOAD\n";
  return "invalid mode $requested_mode\n";
}


However, it seems that in this case the AUTOLOAD method always runs after
the appropriate run mode, and its second argument is undefined. For example:


% ./app.pl rm=mode2
Content-Type: text/html; charset=ISO-8859-1

running mode2
running AUTOLOAD
Use of uninitialized value in concatenation (.) or string at ../lib/Credentials/App.pm line 18.


% ./app.pl rm=foo
running AUTOLOAD
Content-Type: text/html; charset=ISO-8859-1

invalid mode foo
running AUTOLOAD
Use of uninitialized value in concatenation (.) or string at ../lib/Credentials/App.pm line 18.


If I name the AUTOLOAD method something else, things work as I expect:


$self->run_modes(
  "mode1" => "mode1",
  "mode2" => "mode2",
  "AUTOLOAD" => "catchall"
);

sub catchall {
  ...
}


% ./app.pl rm=mode2
Content-Type: text/html; charset=ISO-8859-1

running mode2


% ./app.pl rm=foo
running AUTOLOAD
Content-Type: text/html; charset=ISO-8859-1

invalid mode foo


Is this expected behavior, or is it a bug? Am I forced to name the AUTOLOAD
method something other than AUTOLOAD? Is there some sort of interaction with
Perl's own AUTOLOAD method?

Thanks.
Joey

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by silent-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ples try:

sub setup{
    my $self = shift;
....
....

    $self->run_modes(
...
        'AUTOLOAD' => \&err, # handle unknown run_mode
        );
}

sub err {
  my ($self, $requested_mode) = @_;
  print STDERR "running AUTOLOAD\n";
  return "invalid mode $requested_mode\n";
}

2008/4/16, rjmorris12@... <rjmorris12@...>:

>
> When creating an AUTOLOAD run mode, I wanted to name the method AUTOLOAD,
> so
> I set up my application module as:
>
>
> sub setup {
>   my ($self) = @_;
>   $self->run_modes([qw/mode1 mode2 AUTOLOAD/]);
>   $self->start_mode("mode1");
> }
>
> sub mode1 { return "running mode1\n"; }
> sub mode2 { return "running mode2\n"; }
> sub AUTOLOAD {
>   my ($self, $requested_mode) = @_;
>   print STDERR "running AUTOLOAD\n";
>   return "invalid mode $requested_mode\n";
> }
>
>
> However, it seems that in this case the AUTOLOAD method always runs after
> the appropriate run mode, and its second argument is undefined. For
> example:
>
>
> % ./app.pl rm=mode2
> Content-Type: text/html; charset=ISO-8859-1
>
> running mode2
> running AUTOLOAD
> Use of uninitialized value in concatenation (.) or string at
> ../lib/Credentials/App.pm line 18.
>
>
> % ./app.pl rm=foo
> running AUTOLOAD
> Content-Type: text/html; charset=ISO-8859-1
>
> invalid mode foo
> running AUTOLOAD
> Use of uninitialized value in concatenation (.) or string at
> ../lib/Credentials/App.pm line 18.
>
>
> If I name the AUTOLOAD method something else, things work as I expect:
>
>
> $self->run_modes(
>   "mode1" => "mode1",
>   "mode2" => "mode2",
>   "AUTOLOAD" => "catchall"
> );
>
> sub catchall {
>   ...
> }
>
>
> % ./app.pl rm=mode2
> Content-Type: text/html; charset=ISO-8859-1
>
> running mode2
>
>
> % ./app.pl rm=foo
> running AUTOLOAD
> Content-Type: text/html; charset=ISO-8859-1
>
> invalid mode foo
>
>
> Is this expected behavior, or is it a bug? Am I forced to name the
> AUTOLOAD
> method something other than AUTOLOAD? Is there some sort of interaction
> with
> Perl's own AUTOLOAD method?
>
> Thanks.
> Joey
>
> #####  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/                 ##
> ##                                                            ##
> ################################################################
>
>

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by silent-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oh, sorry, you already know that

2008/4/16, Silent <silent2600@...>:

>
> ples try:
>
> sub setup{
>     my $self = shift;
> ....
> ....
>
>     $self->run_modes(
> ...
>         'AUTOLOAD' => \&err, # handle unknown run_mode
>         );
> }
>
> sub err {
>   my ($self, $requested_mode) = @_;
>   print STDERR "running AUTOLOAD\n";
>   return "invalid mode $requested_mode\n";
> }
>
> 2008/4/16, rjmorris12@... <rjmorris12@...>:
> >
> > When creating an AUTOLOAD run mode, I wanted to name the method
> > AUTOLOAD, so
> > I set up my application module as:
> >
> >
> > sub setup {
> >   my ($self) = @_;
> >   $self->run_modes([qw/mode1 mode2 AUTOLOAD/]);
> >   $self->start_mode("mode1");
> > }
> >
> > sub mode1 { return "running mode1\n"; }
> > sub mode2 { return "running mode2\n"; }
> > sub AUTOLOAD {
> >   my ($self, $requested_mode) = @_;
> >   print STDERR "running AUTOLOAD\n";
> >   return "invalid mode $requested_mode\n";
> > }
> >
> >
> > However, it seems that in this case the AUTOLOAD method always runs
> > after
> > the appropriate run mode, and its second argument is undefined. For
> > example:
> >
> >
> > % ./app.pl rm=mode2
> > Content-Type: text/html; charset=ISO-8859-1
> >
> > running mode2
> > running AUTOLOAD
> > Use of uninitialized value in concatenation (.) or string at
> > ../lib/Credentials/App.pm line 18.
> >
> >
> > % ./app.pl rm=foo
> > running AUTOLOAD
> > Content-Type: text/html; charset=ISO-8859-1
> >
> > invalid mode foo
> > running AUTOLOAD
> > Use of uninitialized value in concatenation (.) or string at
> > ../lib/Credentials/App.pm line 18.
> >
> >
> > If I name the AUTOLOAD method something else, things work as I expect:
> >
> >
> > $self->run_modes(
> >   "mode1" => "mode1",
> >   "mode2" => "mode2",
> >   "AUTOLOAD" => "catchall"
> > );
> >
> > sub catchall {
> >   ...
> > }
> >
> >
> > % ./app.pl rm=mode2
> > Content-Type: text/html; charset=ISO-8859-1
> >
> > running mode2
> >
> >
> > % ./app.pl rm=foo
> > running AUTOLOAD
> > Content-Type: text/html; charset=ISO-8859-1
> >
> > invalid mode foo
> >
> >
> > Is this expected behavior, or is it a bug? Am I forced to name the
> > AUTOLOAD
> > method something other than AUTOLOAD? Is there some sort of interaction
> > with
> > Perl's own AUTOLOAD method?
> >
> > Thanks.
> > Joey
> >
> > #####  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/                 ##
> > ##                                                            ##
> > ################################################################
> >
> >
>

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by Perrin Harkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Apr 15, 2008 at 11:09 PM,  <rjmorris12@...> wrote:
>  Am I forced to name the AUTOLOAD
>  method something other than AUTOLOAD?

Doctor, it hurts when I do this...

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by rjmorris12 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Perrin Harkins <perrin@...> wrote on Wed, Apr 16, 2008 at 09:30:48AM -0400:
> On Tue, Apr 15, 2008 at 11:09 PM,  <rjmorris12@...> wrote:
> >  Am I forced to name the AUTOLOAD
> >  method something other than AUTOLOAD?
>
> Doctor, it hurts when I do this...

:)  Yes, I realize it seems somewhat trivial, but here's my rationale: If I
must name the AUTOLOAD method something other than AUTOLOAD, then I am
forced to use the hash version of run_modes() in setup(). Since all my
run mode methods have the same name as the run modes themselves, I must
enter each run mode's name twice:

  $self->run_modes(
    "mode1" => "mode1",
    "mode2" => "mode2",
    "AUTOLOAD" => "catchall"
  );
     
instead of:
     
  $self->run_modes([qw/
    mode1
    mode2
    AUTOLOAD
  /]);

I'd prefer to do without the redundancy. I can of course live with it or
come up with workarounds, but I wanted to check whether this might be a bug
before going one of those routes.

*Really* what I want to do (and now the truth comes out) is use
CAP::AutoRunmode like this:

  # no need for run_modes() in setup()
 
  sub mode1 : Runmode {}
  sub mode2 : Runmode {}
  sub AUTOLOAD : Runmode {}

but that suffers the same problem. I can come up with a workaround:

  $self->run_modes("AUTOLOAD" => "catchall");

  sub mode1 : Runmode {}
  sub mode2 : Runmode {}
  sub catchall {}

which isn't too bad. But if the AUTOLOAD problem is a bug that can be fixed
easily, then I'd rather do that than use this workaround. Another possible
solution would be to add an AutoloadRunmode attribute to CAP::AutoRunmode:

  # no need for run_modes() in setup()
 
  sub mode1 : Runmode {}
  sub mode2 : Runmode {}
  sub catchall : AutoloadRunmode {}

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by Perrin Harkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 16, 2008 at 11:30 AM,  <rjmorris12@...> wrote:
> Perrin Harkins <perrin@...> wrote on Wed, Apr 16, 2008 at 09:30:48AM -0400:
>   $self->run_modes("AUTOLOAD" => "catchall");
>
>   sub mode1 : Runmode {}
>   sub mode2 : Runmode {}
>   sub catchall {}

I'm not a fan of sub attributes, but that looks pretty good to me.

>  But if the AUTOLOAD problem is a bug that can be fixed
>  easily, then I'd rather do that than use this workaround.

I have no idea if it's a bug or not, but a sub called AUTOLOAD has a
well-known meaning in Perl which you are not entirely following here,
and that seems very confusing to me.  It's kind of like wanting to
call your custom cleanup method DESTROY.

Or maybe I just have a chip on my shoulder because I think obsession
with syntax is one of the more self-destructive traits of the Perl
community.

- Perrin

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by rjmorris12 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Perrin Harkins <perrin@...> wrote on Wed, Apr 16, 2008 at 11:48:42AM -0400:
> I have no idea if it's a bug or not, but a sub called AUTOLOAD has a
> well-known meaning in Perl which you are not entirely following here,
> and that seems very confusing to me.  It's kind of like wanting to
> call your custom cleanup method DESTROY.

The problem is that I didn't choose the name AUTOLOAD for the run mode. It's
the name required by CGI::Application. From the docs:

  If CGI::Application is asked to go to a run mode which doesn't exist it will
  usually croak() with errors. If this is not your desired behavior, it is
  possible to catch this exception by implementing a run mode with the
  reserved name "AUTOLOAD"

So to make use of the AUTOLOAD functionality in CGI::Application, I cannot
give my AUTOLOAD sub the same name as the run mode (unless this is a bug).
Thus I lose the advantages (however small) such a set up might have offered
me. Perhaps it would have been better to reserve a name other than AUTOLOAD
for this purpose. I don't know all the details and haven't considered other
contexts, so I can't say.

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by Darin McBride-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On April 16, 2008 09:48:42 am Perrin Harkins wrote:
> >  But if the AUTOLOAD problem is a bug that can be fixed
> >  easily, then I'd rather do that than use this workaround.
>
> I have no idea if it's a bug or not, but a sub called AUTOLOAD has a
> well-known meaning in Perl which you are not entirely following here,
> and that seems very confusing to me.  It's kind of like wanting to
> call your custom cleanup method DESTROY.

This looks like a minor bug to me - CA is reusing a well-known meme in a way
that doesn't quite work.  When I started using CA, the ability to just
specify runmodes and subs that were the same name didn't exist, so having
C<AUTOLOAD => \&catchall> was not any worse than also having to specify
C<myrunmode => \&myrunmode>.  Now, there is an indirect implicit suggestion
to use a sub called 'AUTOLOAD' to handle the 'AUTOLOAD' action, based on the
perldoc:

           Often, it makes good organizational sense to have your run modes
           map to methods of the same name.  The array-ref interface provides
           a shortcut to that behavior while reducing verbosity of your code.

My suggestion is that AUTOLOAD is not, and never has been, a runmode.  No one
should be able to load http://myapp.net/?rm=AUTOLOAD.  I've not tested to see
if that actually calls the AUTOLOAD runmode or not, but it shouldn't.  (I
suspect it does.)

Instead, if I want the fallback, I should not be setting a run_mode, I should
be setting a fallback:

            $self->fallback_mode('my_catchall_sub');

This is something that should be callable only in cases where the fallback is
required.

Something like this:

-------------------
--- Application.pm.orig 2008-04-16 10:15:17.000000000 -0600
+++ Application.pm 2008-04-16 10:32:13.000000000 -0600
@@ -135,14 +135,14 @@
 
  my $rmeth;
  my $autoload_mode = 0;
- if (exists($rmodes{$rm})) {
+ if (exists($rmodes{$rm}) and $rm ne 'AUTOLOAD') {
  $rmeth = $rmodes{$rm};
  } else {
- # Look for run mode "AUTOLOAD" before dieing
- unless (exists($rmodes{'AUTOLOAD'})) {
+ # Look for fallback mode before dieing
+        $rmeth = $self->fallback_mode();
+ unless ($rmeth) {
  croak("No such run mode '$rm'");
  }
- $rmeth = $rmodes{'AUTOLOAD'};
  $autoload_mode = 1;
  }
 
@@ -526,6 +526,24 @@
 }
 
 
+sub fallback_mode {
+ my $self = shift;
+ my ($fallback_mode) = @_;
+
+ # First use?  Create new __FALLBACK_MODE
+ $self->{__FALLBACK_MODE} = undef unless (exists($self->{__FALLBACK_MODE}));
+
+ # If data is provided, set it.
+ if (defined($fallback_mode)) {
+ $self->{__FALLBACK_MODE} = $fallback_mode;
+ }
+
+    # if we have a fallback, use it, if we have the old deprecated
+    # AUTOLOAD mode, use that instead.
+    return $self->{__FALLBACK_MODE} || {$self->run_modes()}{AUTOLOAD};
+}
+
+
 sub tmpl_path {
  my $self = shift;
  my ($tmpl_path) = @_;
-------------------

Of course, CAP::AutoRunmode would need a flag for that, too - I'm not
providing a sample patch for that ;-)

> Or maybe I just have a chip on my shoulder because I think obsession
> with syntax is one of the more self-destructive traits of the Perl
> community.

Sometimes that obsession finds holes.  And, depending on how poorly your
autoload is written, that hole may be security-related.

But, in reality, syntax is about communication between author and computer.  
And clear, concise syntax is about maintainability.  I wish my coworkers were
as concerned with syntax as many in the Perl community.

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by Rhesa Rozendaal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

rjmorris12@... wrote:

> Perrin Harkins <perrin@...> wrote on Wed, Apr 16, 2008 at 09:30:48AM -0400:
>> On Tue, Apr 15, 2008 at 11:09 PM,  <rjmorris12@...> wrote:
>>>  Am I forced to name the AUTOLOAD
>>>  method something other than AUTOLOAD?
>> Doctor, it hurts when I do this...
>
> :)  Yes, I realize it seems somewhat trivial, but here's my rationale: If I
> must name the AUTOLOAD method something other than AUTOLOAD, then I am
> forced to use the hash version of run_modes() in setup(). Since all my
> run mode methods have the same name as the run modes themselves, I must
> enter each run mode's name twice:
>
>   $self->run_modes(
>     "mode1" => "mode1",
>     "mode2" => "mode2",
>     "AUTOLOAD" => "catchall"
>   );
>      
> instead of:
>      
>   $self->run_modes([qw/
>     mode1
>     mode2
>     AUTOLOAD
>   /]);


You can do both:

   $self->run_modes([qw/ an array /]);
   $self->run_modes( a_single => 'named_mode' );

run_modes() is additive, so this sets up three (3) run modes.

rhesa

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by rjmorris12 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Darin McBride <dmcbride@...> wrote on Wed, Apr 16, 2008 at 10:38:19AM -0600:
> My suggestion is that AUTOLOAD is not, and never has been, a runmode.  No one
> should be able to load http://myapp.net/?rm=AUTOLOAD.  I've not tested to see
> if that actually calls the AUTOLOAD runmode or not, but it shouldn't.  (I
> suspect it does.)

I agree that AUTOLOAD shouldn't be treated as a runmode. And yes, loading
http://myapp.net/?rm=AUTOLOAD does call the AUTOLOAD runmode. The sub gets
called with an undefined value for its second argument.

> Instead, if I want the fallback, I should not be setting a run_mode, I should
> be setting a fallback:
>
>             $self->fallback_mode('my_catchall_sub');
>
> This is something that should be callable only in cases where the fallback is
> required.

I think this is an excellent solution. Thanks for the patch. I did have one
problem with it, though. I got a syntax error on this line (in Perl 5.8.8):

  return $self->{__FALLBACK_MODE} || {$self->run_modes()}{AUTOLOAD};

Just to get it running, I changed it to this (though I'm guessing there's a
slicker way):

  if ($self->{__FALLBACK_MODE}) {
    return $self->{__FALLBACK_MODE};
  }
  else {
    my %rmodes = ($self->run_modes());
    return $rmodes{AUTOLOAD};
  }

#####  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: can AUTOLOAD sub be named AUTOLOAD?

by Ron Savage :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

>   return $self->{__FALLBACK_MODE} || {$self->run_modes()}{AUTOLOAD};
>
> Just to get it running, I changed it to this (though I'm guessing there's a
> slicker way):
>
>   if ($self->{__FALLBACK_MODE}) {
>     return $self->{__FALLBACK_MODE};
>   }
>   else {
>     my %rmodes = ($self->run_modes());
>     return $rmodes{AUTOLOAD};
>   }

Will this work, even though it looks tacky to me:

return $self->{__FALLBACK_MODE} || 
do {
    my %rmodes = ($self->run_modes());
    return $rmodes{AUTOLOAD};
}
--
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: can AUTOLOAD sub be named AUTOLOAD?

by Mark Stosberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 2008-04-16 at 10:38 -0600, Darin McBride wrote:

> On April 16, 2008 09:48:42 am Perrin Harkins wrote:
> > >  But if the AUTOLOAD problem is a bug that can be fixed
> > >  easily, then I'd rather do that than use this workaround.
> >
> > I have no idea if it's a bug or not, but a sub called AUTOLOAD has a
> > well-known meaning in Perl which you are not entirely following here,
> > and that seems very confusing to me.  It's kind of like wanting to
> > call your custom cleanup method DESTROY.
>
> This looks like a minor bug to me - CA is reusing a well-known meme in a way
> that doesn't quite work.  When I started using CA, the ability to just
> specify runmodes and subs that were the same name didn't exist, so having
> C<AUTOLOAD => \&catchall> was not any worse than also having to specify
> C<myrunmode => \&myrunmode>.  Now, there is an indirect implicit suggestion
> to use a sub called 'AUTOLOAD' to handle the 'AUTOLOAD' action, based on the
> perldoc:
>
>            Often, it makes good organizational sense to have your run modes
>            map to methods of the same name.  The array-ref interface provides
>            a shortcut to that behavior while reducing verbosity of your code.
>
> My suggestion is that AUTOLOAD is not, and never has been, a runmode.  No one
> should be able to load http://myapp.net/?rm=AUTOLOAD.  I've not tested to see
> if that actually calls the AUTOLOAD runmode or not, but it shouldn't.  (I
> suspect it does.)
>
> Instead, if I want the fallback, I should not be setting a run_mode, I should
> be setting a fallback:
>
>             $self->fallback_mode('my_catchall_sub');
>
> This is something that should be callable only in cases where the fallback is
> required.
>
> Something like this:

I don't plan to add this patch for the following reasons:

- As mentioned already, run_modes() is additive, you can use the
arrayref call for declaring most methods as a 1-to-1 mapping, and add *1
line of code* to declare the AUTOLOAD method if you need to.

- error_mode() already works an awful lot like fallback_method().
Perhaps it could work for you?

- Seeing that the current functionality of "AUTOLOAD" is "deprecated"
either means that we will continue to support two ways of doing the same
thing, which can make the documentation more verbose and confusing, or
we would drop support for the current functionality at some point, which
people have been using for several years, breaking backward
compatibility, but making the docs and code both simpler again.

Overall, I don't find the change compelling enough to update the API.
But as usual, I will continue to listen the community conversation, and
am open to be swayed in my opinion if there is a strong feeling about
this from others.  

   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: Re: can AUTOLOAD sub be named AUTOLOAD?

by rjmorris12 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mark Stosberg <mark@...> wrote on Thu, Jun 12, 2008 at 10:10:55AM-0400:
> I don't plan to add this patch for the following reasons:

FYI, the patch Mark is referencing is one I posted to the CPAN tracker last
night: http://rt.cpan.org/Public/Bug/Display.html?id=36669


> - As mentioned already, run_modes() is additive, you can use the
> arrayref call for declaring most methods as a 1-to-1 mapping, and add *1
> line of code* to declare the AUTOLOAD method if you need to.

I agree that it's fairly simple to declare the AUTOLOAD method currently,
but I don't think the current design is the proper one. I agree with
Darin's assertion that the AUTOLOAD method should not be a runmode, that is,
it shouldn't be callable via http://myapp.net/?rm=AUTOLOAD. However, I can
accept that this may not be enough justification to change the API. If
others don't find this patch useful, then I can maintain my patches locally
(or decide it's not worth it and use the official release).

This all came up because I wanted to use CAP::AutoRunmode and not specify
*any* run modes. I have a patch for CAP::AutoRunmode as well to support the
fallback_mode, which I can post if others are interested.

Joey

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

LightInTheBox - Buy quality products at wholesale price