[Catalyst] Chained actions question

Matt S Trout dbix-class at trout.me.uk
Fri Aug 25 22:23:38 CEST 2006

leonard.a.jaffe at jpmchase.com wrote:
> I haven't asked a question in a couple of days, so I figured you were 
> all going through withdrawal, and I'd hook you up.
> I am thinking about some restful URLs for a particular bit of a screen 
> I'm working on.
> It is a master detail edit/view screen, and I want to be able to specify 
> the master record via its primary key (id), or its date (report_date - 
> I only ever want to refer to the detail records by their PKs (id).
> The report has an id, a date, and a presenter
> The issue has issue detail, an id, and a report_id foreign key.
> My screen shows a list of all of the issues for a particular status report.
> I need to be able to handle URLs like these:
> 1) /report/9/                                          -   displays all 
> the master/detail screen  for master(9) and all of its detail children
> 2) /report/2006/08/22                        -   likewise for 
> master(2006-08-22) and all of its detail children
> 3) /report/add/                                    -   inserts a new 
> master record for today's date
> 4) /report/9/add/                           -  inserts an issue for 
> master(9)
> 5) /report/2006/08/22/add         -   inserts an issue for 
> master(2006/08/22)
> [ likewise for update of issue data]
> 6) /report/9/edit/3                                   - displays the 
> screen for master(9) with issue(3) loaded into the issued add/edit form.
> 7) /report/2006/08/22/edit/3                - displays the screen for 
> master(2006/08/22) with issue(3) loaded into the issued add/edit form.
> Now, I'm not entirely sure I wan tot use the numeric id columns as part 
> of the URLs since I can be passing the date around on the URL, or in the 
> session, but that might just be my reaction to not being bale to write 
> working action declarations.
> But I've been unable to work out the proper method declarations to 
> create this setup as Chained actions, which is what calls to me whenever 
> I see restful URLs like these.  What is currently stumping me is trying 
> to use either 1 or 3 args for the report key.
> Has anybody done this kind of setup before?
> Any hints would be greatly appreciated.

sub base :Chained('/') :PathPart('report') :CaptureArgs(0)

sub master_by_id :Chained('base') :PathPart('') :CaptureArgs(1)

sub master_by_date :Chained('base') :PathPart('') :CaptureArgs(3)

then you'd set up a controller base-class for your actual actions with their 
own 'base' action, and declare one as chained off of master_by_id and the 
other off of master_by_date

That might seem like unnecessary duplication, but it's -really- handy in terms 
of doing uri_for($action, ...) because it allows you to explicitly specify 
which path you're following.

      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +

More information about the Catalyst mailing list