[Catalyst] Multiple/Dynamic namespace for a Controller?

Phillip Karlsson phillip at dumbrellahosting.com
Thu Oct 1 19:06:09 GMT 2009


hi.

I'm relatively new to Catalyst, so please let me know if my questions  
below show a complete misunderstanding of my options.

Situation:
I'm converting my existing site(s) from HTML::Mason to Catalyst.  I'm  
continuing (for sanity purposes) to use Mason for Views, but I'm  
trying to move as much else as possible into Controllers.

Specifically, I host a bunch of comic strips at different sites and  
different URLs.  To do this currently, I have Mason set up with  
multiple document roots.  One that is my shared "template" path, and  
one that varies based on which site is being requested.  This much I  
have working within my Catalyst setup, and it turned out to be  
(relatively) simple.  Especially given the amount of cruft the  
existing code has built up over the past 7...9...many years.

Problem:
Where I'm currently stymied is with the actual comics on these sites.   
Each creator/site that I host can both have whatever URL they want for  
their comic archives (under which path additional comic functionality  
(random strip, postcards, transcription, etc) also lives) as well as  
possibly having more than one comic on their site.

So, for example site A may have a single comic at:
a.com/				(index comic, today's strip)
a.com/archive/			(previous strip)
a.com/archive/yymmdd.html	(a specific strip)

and site B might have:
b.com/				(index comic, today's strip)
b.com/comics/			(previous strip)
b.com/comics/yyyymmdd.html	(a specific strip)
b.com/sunday/			(different comic, most recent strip)
b.com/sunday/year_week.html	(a specific strip)

In Mason, the way I handled this was to have a root dhandler that  
would check if the (unmatched) URL matched a Regex of known "comic  
paths" for this site and if so would do further processing to figure  
out all the details (which comic, action, strip, etc.)

I can see a direct conversion into Catalyst of creating a default  
action at the root of my application that would do the exact same  
thing, but that feels very un-catalysty to me, given what I've learned  
so far.

It seems this kind of URL structure _should_ fit right into the  
existing Dispatch mechanism for some sort of Comic controller, except  
that:
  - the namespace for this controller would be different depending on  
which site was being requested.
  - the controller might need to get called for multiple "namespaces"  
if the site has more than one comic.

Current thoughts revolve around making some sort of DynamicNamespace  
option for either a DispatchType or an Attribute for Actions (or  
preferably something that could be applied to a Controller as a whole)  
that would be initialized with the relevant namespace(s) per request  
before dispatching, and then... I get stuck.

Thoughts on either how to get this system to work, or better  
alternatives would be very much appreciated.

thanks,
-Phillip

------------------------------------
- Phillip Karlsson                 -
- http://www.dumbrellahosting.com/ -
------------------------------------




More information about the Catalyst mailing list