[Catalyst] To plugin or not to plugin; style/best-practices

A. Pagaltzis pagaltzis at gmx.de
Fri Dec 16 16:03:12 CET 2005


* apv <apv at sedition.com> [2005-12-14 01:20]:
> I'm working on a user supplied comment. I want to apply some
> auto formatting to it (paras but with somewhat complicated
> rules for where they go, no simple splitting on "\n\n," so it's
> not going to be very compact code) in addition to HTML
> sanitizing.
> 
> Should this be a plugin or a controller? If a plugin makes
> sense, is there one already out there I should look at for good
> learning code?

Conceptually, it’s the model’s concern: all views should receive
a consistent view at the transformed data. If you don’t want to
sully the database-level model with formatter specifics, you can
well use a two-layered model, where the bottom layer is purely
for storage, and the upper layer knows the formatter specifics
and talks to this lower layer. Then you can have all views
querying the upper layer for data, whereas controllers stick new
input into the bottom layer.

This plays well to my personal maxime for such cases: “always
keep an unmunged copy of the user input.” Of course, you don’t
want to transform it for each view anew; so the formatter-aware
upper level contains cache logic to keep copies of transformed
output, and when the bottom model layer talks to its listeners
about new data, the upper layer can invalidate its pertinent
cached copies.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



More information about the Catalyst mailing list