[Catalyst] auto() confusion [in 5.33]

Bill Moseley moseley at hank.org
Fri Nov 11 19:43:53 CET 2005


On Fri, Nov 11, 2005 at 05:03:22PM +0000, Chisel Wright wrote:
> Yeah, I corrected this, but the problem was with the arguments being
> passed to auto()

They are passed the same arguments that get setup for the request.
For "default" action it's the entire path, otherwise it's the arguments.

> Before I added the list() function it was seeing 'report', 'list', '15'
> After I added the list() function it was only seeing '15'.

You must have something else you didn't show  -- did you define a
default() in ::Report?  Otherwise, that auto() method you showed
would not run, IIRC.

That is:

In App:

    sub auto : Private { warn "in app auto\n" }
    sub default: Private { warn "in App default\n" }

In C::Report:

    sub auto : Private { warn "in C::Report::auto()\n" }
    sub list : Local { warn "in C::Report::list()\n" }


moseley at bumby:~/temp/App$ script/app_test.pl  /report/fish/15 >/dev/null
in app auto
in App default

Auto didn't run in ::Report.

moseley at bumby:~/temp/App$ script/app_test.pl  /report/list/15 >/dev/null
in app auto
in C::Report::auto()
in C::Report::list()

So you can see that ::Report::auto is not running in the first case.

Running with Debug will show the same thing:


[Fri Nov 11 10:24:09 2005] [catalyst] [debug] Arguments are "report/fish/15"
[Fri Nov 11 10:24:09 2005] [catalyst] [debug] "GET" request for "report/fish/15" from 127.0.0.1
[Fri Nov 11 10:24:09 2005] [catalyst] [info] Request took 0.056969s (17.553/s)
.------------------------------------------------------------------+-----------.
| Action                                                           | Time      |
+------------------------------------------------------------------+-----------+
| /auto                                                            | 0.004996s |
| /default                                                         | 0.007139s |
'------------------------------------------------------------------+-----------'


[Fri Nov 11 10:24:40 2005] [catalyst] [debug] Arguments are "15"
[Fri Nov 11 10:24:40 2005] [catalyst] [debug] "GET" request for "report/list/15" from 127.0.0.1
[Fri Nov 11 10:24:40 2005] [catalyst] [info] Request took 0.070284s (14.228/s)
.------------------------------------------------------------------+-----------.
| Action                                                           | Time      |
+------------------------------------------------------------------+-----------+
| /auto                                                            | 0.016947s |
| /report/auto                                                     | 0.004976s |
| /report/list                                                     | 0.005458s |
'------------------------------------------------------------------+-----------'



But if you throw in a default in ::Report then ::Report's auto will run:


[Fri Nov 11 10:19:20 2005] [catalyst] [debug] Arguments are "report/fish/15"
[Fri Nov 11 10:19:20 2005] [catalyst] [debug] "GET" request for "report/fish/15" from 127.0.0.1
[Fri Nov 11 10:19:20 2005] [catalyst] [info] Request took 0.058822s (17.000/s)
.------------------------------------------------------------------+-----------.
| Action                                                           | Time      |
+------------------------------------------------------------------+-----------+
| /auto                                                            | 0.004368s |
| /report/auto                                                     | 0.004850s |
| /report/default                                                  | 0.004285s |
'------------------------------------------------------------------+-----------'

And you can see how the arguments change when default is used.


> What I don't grok is why adding a new function affects the arguments
> being passed to a different, already written, function.

Only if there's a "match".


> Should I be movind to using names parameters int he URL? I just want to
> run a check in auto() that boils down to "is this user allowed to view
> this client?"

Something that works for both default and non-default actions?

Not so sure this will work in the general case, but maybe just shift
the args if it's a default action?

sub auto : Private {
    my ($self, $c, @args ) = @_;
    if ( $c->action->name eq 'default' ) {
        @namespace = split m!/!, $c->action->namespace;
        splice @args, 0, @namespace;
    }

    my $client_id = shift @args;




-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list