[Catalyst] [OT] ASP.NET MVC

Matt S Trout dbix-class at trout.me.uk
Mon Dec 17 20:55:17 GMT 2007


On Mon, Dec 17, 2007 at 07:31:21AM -0800, John Napiorkowski wrote:
> Yeah, the main configuration is definitely the right
> place to be maintain centralized routing and to more
> cleanly separate the URI namespace.  Just that as you
> say, it's not clear to people when they first start
> probably because there isn't a lot of people saying
> that and the documentation and quick start guides
> don't seem to promote that idea.

No, it's absolutely and horribly the wrong place - that's why nobody uses
the feature even though it's supported. It basically turns your main mapping
into a god object; why does the mapping info for the admin interface need to
be related in any way shape or form to the mapping for the user interface,
for example?

Self-contained URI mapping info for controllers is essential to encapsulated
code re-use.

The one time I tend to use the main app config to supply such info is to
rename a particular part of a site for a specific deployment - for e.g.
if I have

MyApp::Controller::Blog::base :Chained('/') :PathPart('blog') :CaptureArgs(0)

I might do

<Controller Blog>
  <Action base>
    PathPart news
  </Action>
</Controller>

to rename that URI segment to /news instead of /blog.

> If you give me a template to start with, either as an
> advent article or other I will definitely try to
> expand it out, as long as you don't me giving it the
> once or twice over.  

I was offering to provide an example of how to use base classes in ways
that are entirely impossible with a crappy central routing system - the
Reaction CRUD controller is a good example of this, it provides

$base/
$base/create
$base/id/*/view
$base/id/*/edit
$base/id/*/delete

actions, where $base is the chain part leading up to 'sub base'

So to bind that in you do

package MyApp::Controller::Admin::Foo

use base qw(Reaction::UI::Controller::CRUD);

__PACKAGE__->config(
  actions => { base => { Chained => '/admin/base', PathPart => 'foo' } },
  ... # model name etc. here
);

and assuming you have

MyApp::Controller::Admin::base :Chained('/') :PathPart('admin') :CaptureArgs(0)

/admin/foo/
/admin/foo/create
/admin/foo/id/*/view
/admin/foo/id/*/edit
/admin/foo/id/*/delete

actions all immediately appear ready to go.

This sort of thing simply isn't possible with a central routing system, which
is why in spite of people periodically claiming they're "easier" I've always
been against the concept.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list