El 21/03/11 20:58, Octavian Rasnita escribió:
Yes, it is very simple to use Mail::Builder::Simple directly, but
there are some advantages when using it in a model:
- You can share the configuration data among more controllers and even external
programs;
You can do it also without the model. Just create a new section in the
application config file:
(YAML):
...
Mail:
from: [email protected]
to: [email protected]
subject: Hello
...
And then from the controller:
...
my $mail = Mail::Builder::Simple->new;
$mail->send(
from => MyApp->config->{Mail}{from},
to => MyApp->config->{Mail}{to},
subject => MyApp->config->{Mail}{subject},,
plaintext => "Hello,\n\nHow are you?\n",
);
...
- You need to write less code in your controllers;
As we can see by the above example, it's more or less the same amount of
code.
- It is more elegant, because it uses the Catalyst style - you don't need to "use
Mail::Builder::Simple" in every controller in which you need to send mail...
I don't buy it, see my former post. The "Catalyst style" does not say
"you should do everything through a Catalyst component". In fact, I find
my way more elegant, since I don't have to think "laterally" in order to
see that by using a Model I'm just sending an email. If I see a Model, I
think of something like a data store, whatever the type. Sending an
email is not like a data store, it's more like a communication device.
From the Catalyst Manual
(http://search.cpan.org/~zarquon/Catalyst-Manual-5.8005/lib/Catalyst/Manual/About.pod#The_MVC_pattern
<http://search.cpan.org/%7Ezarquon/Catalyst-Manual-5.8005/lib/Catalyst/Manual/About.pod>):
"...
The purpose of the *Model* is to access and modify data. Typically the
Model will interact with a relational database, but it's also common to
use other data sources, such as the Xapian
<http://search.cpan.org/perldoc?Catalyst%3A%3AModel%3A%3AXapian> search
engine or an LDAP server.
..."
I don't think sending an email is anything like accessing or modifying data.
But of course, this is perl. TIMTOWTDY. :-)
Regards
J.
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/