Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Newbie Catalyst dispatch question

by mobiusinversion (Beadle)
on Jun 23, 2012 at 01:11 UTC ( [id://977915]=perlquestion: print w/replies, xml ) Need Help??

mobiusinversion has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have a question regarding basic Catalyst dispatching. Lets say I have a public url like this:
/app/reporting/42
Which displays reports about the account with account_id 42. I tried this:
package MyApp::Controller::App::Reporting; use Moose; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } sub reporting :Chained('chained_index') PathPart('reporting') Args(1) +{ my( $self, $c, $account_id ) = @_; $c->log->debug( "Generating report for account $account_if" ); }
But when I fire up my Catalyst servers I see this:
[debug] Unattached Chained actions: .-------------------------------------+------------------------------- +-------. | Private | Missing parent + | +-------------------------------------+------------------------------- +-------+ | /app/reporting/reporting | /app/reporting/chained_index + | '-------------------------------------+------------------------------- +-------'
My question is how do I go about creating a method that will handle requests to urls of the form /app/reporting/id, In general I am trying to wrap my head around Catlayst controllers, in particular, how to structure controller for paths. Eventually (next week) I'll need to do create controllers to handle requests like:
/app/reporting/42/product_group/foo/product/bar
that will need to report on account id 42, product group id 'foo' and product id 'bar'. How would I do this? Thanks in advance for the help monks. Any help in the right direction would be awesome. I'm reading the docs but still not getting it.

Replies are listed 'Best First'.
Re: Newbie Catalyst dispatch question
by Your Mother (Archbishop) on Jun 23, 2012 at 03:44 UTC

    The docs are much better than they used to be but they still require too much caffeine to absorb. Chained Examples.

    package MyApp::Controller::App::Reporting; use Moose; use namespace::autoclean; BEGIN { extends "Catalyst::Controller" } sub by_id :Chained("/") :PathPart("reporting") :CaptureArgs(1) { my( $self, $c, $id ) = @_; $c->stash( ohaid => $id ); } sub reporting :Chained("by_id") PathPart("") Args(0) { my( $self, $c ) = @_; $c->response->body("OHAI " . $c->stash->{ohaid}); } __PACKAGE__->meta->make_immutable; __END__ [debug] Loaded Chained actions: .-------------------------------------+------------------------------- +-------. | Path Spec | Private + | +-------------------------------------+------------------------------- +-------+ | /reporting/* | /app/reporting/by_id (1) + | | | => /app/reporting/reporting + | '-------------------------------------+------------------------------- +-------' moo@cow[1148]~>curl http://localhost:3000/reporting/DER OHAI DER

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://977915]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-23 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found