Totally depends. I ported an app to Catalyst that previously was
basically one-action-per-controller. It cannot be called anything
less than a lot of work, but it paid of royally. The code is as
DRY as it was before, but it’s now far better structured.
Previously it was blocks of if-elsif chains grouping together
execution steps that are shared by some URIs but not others – now
it’s Chained. A typical controller looks something like this:
sub base : Chained PathPart('doc') CaptureArgs(0) { ... }
sub list : Chained('base') PathPart('') Args(0) { ... }
sub item : Chained('base') PathPart('') CaptureArgs(1) { ... }
sub view : Chained('item') PathPart('') Args(0) { ... }
sub edit : Chained('item') Args(0) { ... }
This gives `/doc` (goes `base` then `list`), `/doc/*` (goes
`base` then `item` then `view`), and `/doc/*/edit` (goes `base`
then `item` then `edit`).
And then you can put stuff shared by all actions in `base`[^1],
and stuff shared by all actions that relate to a single document
(eg. stuffing that document into the stash) all in `item`.
By liberal use of `PathPart('') CaptureArgs(0)` you can force any
URI to step down any number of intermediate steps you require, so
you can use that to group together shared code any way you see
fit:
sub foo : Chained CaptureArgs(0) {}
sub bar : Chained('foo') PathPart('') CaptureArgs(0) {}
sub baz : Chained('bar') PathPart('') CaptureArgs(0) {}
sub qux : Chained('baz') Args(0) {}
This will dispatch `/foo/qux` across the entire foo bar baz qux
chain. Now consider:
...
This is the best example I've seen! It would be great if you could
write this up and put it in the manual or wiki!
I think I finally know how chained works :-)
thanks!
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/