[Catalyst] So, what things make Catalyst cool for you?

Thomas L. Shinnick tshinnic at io.com
Sun Oct 30 22:49:46 CET 2005


At 15:02 10/30/2005, Sam Vilain wrote:
>On Sat, 2005-10-29 at 23:14 +0100, Pedro Melo wrote:
>> > 1. The method to uri mapping is just awesome. :)
>> >     sub foo : Path('/index.html') {}
>> >     sub foo : Global {}
>> >     sub foo : Local {}
>> >     sub foo : Regex('^(.*)\.html$') {}
>> this is one of the best things. It makes a very clean code base with 
>> enforced separation of actions per method.
>
>It also could make finding entry points for a given path very hard in an
>application which is "somebody else's".
>
>How is resolving this typically solved on a Catalyst code base?  Do you
>compile the app and ask it for its URI mapping, or simply "try to keep
>it under control" ?

When the debug option is enabled Catalyst displays all the information you need in the initial display.  The initial debug display sections are:
[Sun...2005] [catalyst] [debug] Loaded dispatcher "Catalyst::Dispatcher"
[Sun...2005] [catalyst] [debug] Loaded engine "Catalyst::Engine::HTTP"
[Sun...2005] [catalyst] [debug] Found home "C:\Archive\Mine\Perl\catalyst1\Widget\trunk"
[Sun...2005] [catalyst] [debug] Loaded tables "widget_sessions wgprogress wgscaliases wgscids wguserroles wgusers wgusersroles wgwidgets"
[Sun...2005] [catalyst] [debug] Loaded components: ....
[Sun...2005] [catalyst] [debug] Loaded private actions:
[Sun...2005] [catalyst] [debug] Loaded public actions:

The "public actions" table will show you the possible URL targets:
[Sun...2005] [catalyst] [debug] Loaded public actions:
.----------------------------------+-----------------------------------.
| Public                           | Private                           |
|=---------------------------------+----------------------------------=|
| /admin/list                      | /admin/list                       |
| /admin/user/add                  | /admin/user/add                   |
| /admin/user/delete               | /admin/user/delete                |
| /admin/user/do_add               | /admin/user/do_add                |
  : : : : : : : 
| /login                           | /login/login                      |
| /logout                          | /login/logout                     |
  : : : : : : : 
| /user/dataupld/suggest           | /user/dataupld/suggest            |
'----------------------------------+-----------------------------------'

You can cross-reference the private targets with implementing components by using the prior listing:

[Sun...2005] [catalyst] [debug] Loaded private actions:
.----------------------------------+-----------------------------------.
| Private                          | Class                             |
|=---------------------------------+----------------------------------=|
| /begin                           | Widget                            |
| /default                         | Widget                            |
| /end                             | Widget                            |
  : : : : : : : 
| /admin/default                   | Widget::C::Admin                  |
| /admin/list                      | Widget::C::Admin                  |
| /admin/end                       | Widget::C::Admin                  |
| /admin/user/add                  | Widget::C::Admin::User            |
| /admin/user/default              | Widget::C::Admin::User            |
| /admin/user/end                  | Widget::C::Admin::User            |
| /admin/user/delete               | Widget::C::Admin::User            |
| /admin/user/do_add               | Widget::C::Admin::User            |
  : : : : : : : 
| /user/dataupld/suggest           | Widget::C::User::DataUpld         |
  : : : : : : : 
| /login/logout                    | Widget::C::Login                  |
| /login/default                   | Widget::C::Login                  |
| /login/login                     | Widget::C::Login                  |
| /login/end                       | Widget::C::Login                  |
'----------------------------------+-----------------------------------'

So it is fairly easy to determine that URLs like "/user/dataupld/suggest" will be handled by component Widget::C::User::DataUpld.  That "/login" will be handled in Widget::C::Login.  Also that unrecognized URLs beginning "/admin/xxxx" will be handled by Widget::C::Admin. 

Just turn on the -Debug option to see Catalyst tell you what it knows.

>In my own URI to handler mapper (on CPAN as PSA::Cache), I use a
>convention that mirrors CGI in style - URIs simply get resolved to
>relative pathnames, with path_info and "index" feature equivalents.  In
>this instance, I preferred convention over flexibility.  It did have its
>drawbacks; for instance moving paths around was often a PITA.  But it
>sure was simple to explain and understand.
>
>Sam.





More information about the Catalyst mailing list