Created
March 18, 2010 14:58
-
-
Save sharifulin/336431 to your computer and use it in GitHub Desktop.
Render, mail and render_local in the Mojolicious
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
get '/' => sub { | |
my $self = shift; | |
$self->main::mail( | |
to => 'To', | |
from => 'From', | |
subject => 'Subject', | |
# msg => 'Body', | |
# template => 'send_mail', # don't work path to tmpl ??? | |
); | |
$self->main::mail( | |
to => 'To2', | |
from => 'From2', | |
subject => 'Subject2', | |
# msg => 'Body', | |
# template => 'send_mail', # don't work path to tmpl ??? | |
); | |
$self->render; | |
} => 'index'; | |
app->renderer->add_handler(mail => sub { | |
my($mojo, $ctx, $output) = @_; | |
warn "----->$_->{to} $_->{from} $_->{subject}\n$_->{msg}<----\n" for $ctx->stash; | |
return 1; | |
}); | |
shagadelic; | |
sub render_local { | |
my $self = shift; | |
my $args = { @_ }; | |
$self->render_partial(@_); | |
delete @{$self->stash}{ keys %$args }; | |
return 1; | |
} | |
sub mail { | |
my $self = shift; | |
my $param = { @_ }; | |
$self->main::render_local( | |
handler => 'mail', | |
format => 'mail', | |
msg => $param->{'msg'} || $self->render_partial(format => 'mail'), | |
map {$_ => $param->{$_ }} qw(from to subject), | |
); | |
return 1; | |
} | |
__DATA__ | |
@@ index.mail.ep | |
% layout 'funky'; | |
Mail Yea baby! | |
@@ index.html.ep | |
% layout 'funky'; | |
Yea baby! | |
@@ layouts/funky.html.ep | |
<!doctype html><html> | |
<head><title>Funky!</title></head> | |
<body><%== content %></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment