Catalyst Controller Questions

纵饮孤独 提交于 2019-12-06 02:18:30

One of the beauties of Catalyst is its flexibility. You can do this however it best suits your application.

If you only have a handful of URLs you support, then there's nothing intrinsically wrong with putting them all in Root.pm. Particularly if there's no depth, ie localhost:3000/foo and localhost:3000/bar

However, as soon as you start to have longer URLs such as localhost:3000/foo/bar/baz/quux where baz and quux are arguments to bar, you'll see the benefit of separating out a Foo.pm that contains an action (sub) called 'bar'. (And that's before we get into the joys of Chained Actions...)

Although there are ways that you can achieve the equivalent of a Rails style routing table, it's not generally considered to be a good idea. Not having a routes table is an intrinsic feature/benefit of Catalyst over other frameworks.

There's a good discussion of this on pages 13-14 of The Definitive Guide to Catalyst. If you don't have this book, you should.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!