[Catalyst] Program the logic

Matt S Trout dbix-class at trout.me.uk
Thu Jun 29 23:09:07 CEST 2006


Nilson Santos Figueiredo Junior wrote:
> On 6/29/06, Brandon Black <blblack at gmail.com> wrote:
>> The approach I'm attempting lately (and I haven't gotten it all
>> working right yet...) is to make Controller base-classes that
>> implement generic concepts for things like paging and sorting tables
>> of data (complete with handling form args like ?page=3&count=50 or
>> ?sortby=foo:desc silently for the controller), which makes it
>> effortless for the controller to apply those sorts of things to the
>> resultset before its sent to the view.  These bits of controller
>> functionality are of course View-agnostic.
> 
> It's View-agnostic but then the View still isn't Controller-agnostic.
> 
> Actually, after some thought this might be the real question that'd
> solve my issues: how to properly decouple Controller from Views?
> 
> I'll give you a real world example that's actually already in use in
> an implemented (but evolving) system. I've got a somewhat generic
> table widget. This table contains items that can be either active or
> closed. Sometimes the closed items should be displayed along the
> active, other times they shouldn't, but there's always a button
> "show/hide closed items". It's currently implemented entirely in the
> View, since the controller IMO shouldn't really need to know if the
> closed items should or shouldn't be displayed.
> 
> That involves doing bad things such as using c.param() from the View
> but it really was the only practical way (i.e. DRY) I could think of.
> So, any suggestions are welcome. ;-)

No, it's the best separation of concerns, I think. The trick is to make the 
View smarter, which is a hard problem for webapps because of the degree of 
flexibility in styling required (ASP.Net has great shiny components, but any 
ASP.Net app looks like an ASP.Net app). Encapsulating the c.param bits in a TT 
plugin or three might be a good halfway measure.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list