Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Catalyst request handling

by redlemon (Hermit)
on Nov 22, 2005 at 15:44 UTC ( #510833=perlquestion: print w/ replies, xml ) Need Help??
redlemon has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks, I'm starting with Catalyst and I'm confused at the moment about how catalyst handles my request.

Basically I ran:

catalyst.pl Greet; cd Greet scripts/greet_create.pl view TT TT scripts/greet_create.pl controller Greeting echo "[% greeting %]" > root/greeting.tt

And edited 'lib/Greet/C/Greeting.pm' so it looks like this:

sub default : Private { my ( $self, $c ) = @_; $c->forward('say'); } sub say : Local { my ( $self, $c ) = @_; $c->stash->{greeting} = join q{, }, @{ $c->req->args() }; $c->stash->{template} = q{greeting.tt}; $c->forward('Greet::V::TT'); }

Now running a couple of scenarios, I get:

1. scripts/greet_test.pl / -> Congratulations, Greet is on Catalyst! 2. scripts/greet_test.pl /greeting/say/hello/world -> hello, world 3. scripts/greet_test.pl /greeting/hello/world -> greeting, hello, world 4. scripts/greet_test.pl /hi/there/greeting/say/hello/world -> hi, there, greeting, say, hello, world

Now, scenario 1 is as expected. I didn't change the main file and it presents the default blurb.

Scenario 2 is also as expected, I run the controller with the say request and it answers me back with the arguments.

But what about scene 3? Why didn't that strip the namespace from the arguments? And I'm really confused about scene 4. I would have expected that to print the same as 1.

Can someone explain this behaviour to me?

--
Lyon

Comment on Catalyst request handling
Select or Download Code
Re: Catalyst request handling
by Anonymous Monk on Nov 22, 2005 at 17:09 UTC
    Scene 3 does that because default doesn't work that way. If you wanted the namespace stripped then you'd do something like
    sub base :Path('') {
    ...
    }

    which will be a path action anchored at /greeting and as such should see args of ('hello', 'world').
    Scene 4, I'm not entirely sure - I wonder if there's a default in your app class picking up the result or similar ...
    - Matt S Trout (mst on irc.perl.org)

      Thanks, your 'base()' suggestion does work indeed.

      There's nothing else in any of the files than whatI described in my question. However, in the mean time I've upgraded to Catalyst 5.57, which does behave as expected. So I guess it was a bug in an earlier version.

      Thanks for explaining.
      --
      Lyon

Re: Catalyst request handling
by chibiryuu (Beadle) on Nov 22, 2005 at 18:13 UTC
    sub default : Private { my ( $self, $c ) = @_; my (undef, @args) = @{$c->req->args}; $c->forward('say', \@args); }
    This make scene 3 behave the way you expect it to.

    But I can't reproduce your scene 4.  (Catalyst 5.56 here.)  Do you have a $c->forward in Greet.pm?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://510833]
Approved by friedo
Front-paged by kutsu
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-07-31 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (250 votes), past polls