prepared for c-p-e 0.07
Marcus Ramberg [Mon, 18 Dec 2006 15:03:30 +0000 (15:03 +0000)]
Changes
Email.pm
MANIFEST
META.yml

diff --git a/Changes b/Changes
index 361b889..95917b6 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,10 +1,13 @@
 Revision history for Perl extension Catalyst::Plugin::Email.
 
-0.06
+0.07  2006-12-18 16:08:00
+       - Revert change:
+          Make it croak if recipient is empty.
+
+0.06  2006-12-06 12:23:00 
         - Added more extensive docs on config and usage.
           (Carl Franks)
-        - Make it croak if recipient is empty.
-        - Change docs to use ->render not subreq
+       - Make it croak if recipient is empty.
 
 0.05  Thu Nov 17 22:00:00 2005
         - Added docs on sending email using a TT template.
index 5f3f34a..d909b53 100644 (file)
--- a/Email.pm
+++ b/Email.pm
@@ -6,7 +6,7 @@ use Email::MIME;
 use Email::MIME::Creator;
 use Carp qw/croak/;
 
-our $VERSION = '0.06';
+our $VERSION = '0.07';
 
 =head1 NAME
 
@@ -64,10 +64,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 +85,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 +102,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,13 +116,13 @@ 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>.
+for HTML pages.  This can be accomplished by pairing this plugin with
+L<Catalyst::Plugin::SubRequest>.
 
 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) 
+file.  The call to $c->subreq makes an internal call to the render_email
+method just like an external call from a browser.  The request will pass
+through the end method to be processed by your View class.
 
     sub send_email : Local {
         my ( $self, $c ) = @_;  
@@ -141,15 +132,20 @@ than TT, consult the docs for your view)
                 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->subreq( '/render_email' ),
         );
         # redirect or display a message
     }
-
+    
+    sub render_email : Local {
+        my ( $self, $c ) = @_;
+        
+        $c->stash(
+            names    => [ qw/andyg sri mst/ ],
+            template => 'email.tt',
+        );
+    }
+    
 And the template:
 
     [%- FOREACH name IN names -%]
@@ -165,7 +161,6 @@ Output:
     Hi, andyg!
     Hi, sri!
     Hi, mst!
-    Hi, ash!
     
     --
     Regards,
@@ -173,7 +168,8 @@ 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
 
index c0ce711..7adb2f4 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2,8 +2,8 @@ Changes
 Email.pm
 Makefile.PL
 MANIFEST                       This list of files
+META.yml                       Module meta-data (added by MakeMaker)
 README
 t/01use.t
 t/02pod.t
 t/03podcoverage.t
-META.yml                                 Module meta-data (added by MakeMaker)
index 5dfe1fe..4fd78a1 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,7 +1,7 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         Catalyst-Plugin-Email
-version:      0.05
+version:      0.07
 version_from: Email.pm
 installdirs:  site
 requires: