modernize these tests
[catagits/Catalyst-Plugin-Email.git] / Email.pm
index 5f3f34a..87b6ca0 100644 (file)
--- a/Email.pm
+++ b/Email.pm
@@ -6,14 +6,16 @@ use Email::MIME;
 use Email::MIME::Creator;
 use Carp qw/croak/;
 
-our $VERSION = '0.06';
+our $VERSION = '0.08';
 
 =head1 NAME
 
-Catalyst::Plugin::Email - Send emails with Catalyst
+Catalyst::Plugin::Email - (DEPRECATED) Send emails with Catalyst
 
 =head1 SYNOPSIS
 
+    # please use Email::MIME::Kit or Catalyst::View::Email::Template instead
+
     use Catalyst 'Email';
 
     __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
@@ -64,10 +66,7 @@ C<create()>.
             To      => 'me@localhost',
             Subject => 'A TT Email',
         ],
-        body => $c->view('TT')->render($c, 'email.tt', {
-           additional_template_paths => [ $c->config->{root} . '/email_templates'],
-           }
-        ),
+        body => $c->subreq( '/render_email' ),
     );
 
 To send a multipart message, include a C<parts> argument containing an 
@@ -88,11 +87,7 @@ arrayref of Email::MIME objects.
                 disposition  => 'attachment',
                 charset      => 'US-ASCII',
             },
-            body => $c->view('TT')->render($c, 'email.tt', {
-               additional_template_paths => [ $c->config->{root} . '/email_templates'],
-               names => [qw/foo bar baz/]
-               }
-            ),
+            body => $c->subreq( '/render_email' ),
         ),
     );
     
@@ -109,8 +104,6 @@ arrayref of Email::MIME objects.
 sub email {
     my $c = shift;
     my $email = $_[1] ? {@_} : $_[0];
-    croak "Can't send mail without recipient"
-       unless length($email->{To});
     $email = Email::MIME->create(%$email);
     my $args = $c->config->{email} || [];
     my @args = @{$args};
@@ -125,31 +118,36 @@ sub email {
 =head1 USING WITH A VIEW
 
 A common practice is to handle emails using the same template language used
-for HTML pages.  This is best accomplished by capturing the output from the
-template. For TT this is done using the C<render> method as described in 
-L<Catalyst::View:TT/CAPTURING TEMPLATE OUTPUT>.
-
-Here is a short example of rendering an email from a Template Toolkit source
-file.  For more information on render (or how to do this with a view other
-than TT, consult the docs for your view) 
+for HTML pages.  If your view supports the 'render' method (Like the TT view 
+does), you just set the body like this:
+  $c->email(
+     header => [
+        To      => 'me@localhost',
+        Subject => 'A TT Email',
+     ],
+     body => $c->view('TT')->render($c,'mytemplate.tt'),
+  }
+
+If your view doesn't support render, you can just forward to it, then reset 
+the body like this:
 
     sub send_email : Local {
         my ( $self, $c ) = @_;  
-
+        {
+        local $c->stash->{names}   = [ qw/andyg sri mst/ ],
+        local $c->stash->{template}= 'mytemplate.tt';   
+        $c->forward($c->view('MyView'));
         $c->email(
             header => [
                 To      => 'me@localhost',
                 Subject => 'A TT Email',
             ],
-            body => $c->view('TT')->render('email.tt',
-             {  additional_template_paths => [ $c->config->{root} . '/email_templates'],
-                names => [ qw/andyg sri mst ash/ ],
-             } ),
-              
+            body => $c->res->body,
         );
-        # redirect or display a message
+        $c->res->body(undef);
+        }
     }
-
+    
 And the template:
 
     [%- FOREACH name IN names -%]
@@ -165,7 +163,6 @@ Output:
     Hi, andyg!
     Hi, sri!
     Hi, mst!
-    Hi, ash!
     
     --
     Regards,
@@ -173,17 +170,15 @@ Output:
 
 =head1 SEE ALSO
 
-L<Catalyst>, L<Catalyst::View::TT>, L<Email::Send>, L<Email::MIME::Creator>
+L<Catalyst>, L<Catalyst::Plugin::SubRequest>, L<Email::Send>,
+L<Email::MIME::Creator>
 
 =head1 AUTHOR
 
 Sebastian Riedel, C<sri@cpan.org>
-
-=head1 THANKS
-
-Andy Grundman - Additional documentation
-
-Carl Franks - Additional documentation
+Andy Grundman
+Carl Franks 
+Marcus Ramberg C<mramberg@cpan.org>
 
 =head1 COPYRIGHT