Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #4311
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Newsgroups | comp.programming |
| Subject | How to refactor email template formatting code? |
| Date | 2014-04-25 00:28 +0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ljbvm0$m26$1@speranza.aioe.org> (permalink) |
I am refactoring Perl code which sends emails. The old code directly created
email text and sent it. Some of this old code used hand-crafted templates
(with Perl s/.../.../ replacements) load from files.
The new code is template-based. I have created the function SendFormattedEmail
which is called like:
SendFormattedEmail(
{
Subject => Bravo::FormattedEmail::EmailTranslate('title.order-cancel-producer', $Language),
To => $ShowData->{'ProducerEmail'},
Bcc => $COUPONS_EMAIL,
Language => $Language,
($Options ? %$Options : ())
},
"cancel_order_producer.tmpl",
\%TemplateVariables
);
Here "cancel_order_producer.tmpl" is a Template Toolkit based template,
%TemplateVariables is the data used by Template Toolkit.
Now I met a code like this:
my ($RetCode, $tmpl) = PaymentInstructions($OrderID, 1, $Hebrew);
return $RetCode if $RetCode;
# ...
# Send email with the body $tmpl
I am confused how to refactor it to a new style:
- Should PaymentInstructionsNew() (the refactored function) return
($RetCode, $TemplateFileName, $TemplateVariables)? (with self suggesting
variable names)
- Should I create function CreateFormattedEmailText() called like the following?
CreateFormattedEmailText(
{
Language => $Language,
($Options ? %$Options : ())
},
"cancel_order_producer.tmpl",
\%TemplateVariables
);
and a version of SendFormattedEmail which sends this already formatted message?
CreateFormattedEmailText() should be called inside PaymentInstructions() to
create the final text (but not headers) of the email
Whatever?
--
Victor Porton - http://portonvictor.org
Back to comp.programming | Previous | Next | Find similar | Unroll thread
How to refactor email template formatting code? Victor Porton <porton@narod.ru> - 2014-04-25 00:28 +0300
csiph-web