[Catalyst-dev] Catalyst plugin

J. Shirley jshirley at gmail.com
Thu Oct 2 03:18:01 BST 2008


On Wed, Oct 1, 2008 at 5:45 PM, Matt S Trout <dbix-class at trout.me.uk> wrote:
> On Wed, Oct 01, 2008 at 10:15:47AM +0300, Octavian Rasnita wrote:
>> And to be more clear what I want, is to create a static module that works outside of Catalyst app, and use that module in the Catalyst view, because I want to be able to use the same interface when sending mail from a cron job, so probabily the part of the module that uses a template should not use Catalyst but Template-Toolkit directly.
>>
>> So, in this case, don't you think it would be better to create another module?
>
> As I said in another email, what I'd say is that you should -subclass-
> C::V::Email or C::V::Email::Template, and if you can't do what you need via
> subclassing, sort out patches to the existing stuff so you can subclass it.
>
> Then the stuff you want is in your own module, but all the stuff the already
> existing modules already do isn't duplicated.
>
> Ain't OO awesome :)
>

The UTF-8 headers is a patch to just run encode('MIME-Header',
$subject), so that's negligible.

It'd be pretty simple to have the template => stuff automatically call
htmltext anyway.  Just subclass C::V::Email::Template and overload
generate_parts... but that isn't everything.  I wouldn't want to
assume that anything template based is html, but that's just me (I'd
rather write one line of code to set the content_type and know for
sure).

Since you said you want a module outside of the Catalyst cycle it
sounds like what you want is something that just runs TT and puts the
output in htmltext in Mail::Builder.  That's pretty trivial, but
splicing it into the Catalyst request cycle may not "fit" well.

Catalyst::View::Email::Template isn't married to TT, and shouldn't be.
 It operates on a Catalyst::View object that is template based (Mason,
TT, etc).

It really just seems that you want is 3 lines of code that just joins
TT and Mail::Builder, which would be fine as a model class (especially
since your TT config would likely be different than your core Catalyst
app anyway).

I could be wrong about the end result, but it seems this is roughly
what you want:
my $tt = Template->new;
my $output;
$tt->process("template.tt", $stash, \$output);
$mail->htmltext($output);



More information about the Catalyst-dev mailing list