Skip to content

Commit

Permalink
add support Mojolicious 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sharifulin committed May 22, 2013
1 parent e6dfc5c commit b69c0ba
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ my $builder = Module::Build->new(
'Test::More' => 0,
},
requires => {
'perl' => 5.008007,
'perl' => 5.001001,
'Encode' => 0,
'MIME::Lite' => 3.027,
'MIME::EncWords' => 0,
'Mojolicious' => 1.17,
'Mojolicious' => 4.0,
},
add_to_cleanup => [],
meta_merge => {
Expand Down
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for Mojolicious-Plugin-Mail

0.95 2013-05-23/01:09
* Mojolicious 4.0 ready

0.94 2012-02-29/16:01
* small fixes

Expand Down
8 changes: 4 additions & 4 deletions META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ name: Mojolicious-Plugin-Mail
provides:
Mojolicious::Plugin::Mail:
file: lib/Mojolicious/Plugin/Mail.pm
version: 0.94
version: 0.95
requires:
Encode: 0
MIME::EncWords: 0
MIME::Lite: 3.027
Mojolicious: 1.17
perl: 5.008007
Mojolicious: 4
perl: 5.001001
resources:
license: http://dev.perl.org/licenses/
repository: http://github.com/sharifulin/Mojolicious-Plugin-Mail
version: 0.94
version: 0.95
4 changes: 2 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Note: this file was auto-generated by Module::Build::Compat version 0.3603
require 5.008007;
require 5.001001;
use ExtUtils::MakeMaker;
WriteMakefile
(
Expand All @@ -12,7 +12,7 @@ WriteMakefile
'Test::More' => 0,
'MIME::EncWords' => 0,
'MIME::Lite' => '3.027',
'Mojolicious' => '1.17',
'Mojolicious' => '4',
'Encode' => 0
}
)
Expand Down
1 change: 1 addition & 0 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Mojolicious::Plugin::Mail - Mojolicious Plugin for send mail
=head1 DESCRIPTION

L<Mojolicous::Plugin::Mail> is a plugin for Mojolicious apps to send mail using L<MIME::Lite>.
Mojolicious 4.0 ready.

=head1 HELPERS

Expand Down
2 changes: 1 addition & 1 deletion example/test.pl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
data => "Привет, это тестовое сообщение от Mojolicious::Plugin::Mail.\n\nРаботает!",
);

$self->render_text('OK');
$self->render(text => 'OK');
};

get '/render' => sub {
Expand Down
2 changes: 1 addition & 1 deletion example/test_attach.pl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
my $self = shift;

my $data = $self->render_mail(template => 'render');
my $att = $self->render_partial('partial');
my $att = $self->render('partial', partial => 1);

warn $self->mail(
mail => {
Expand Down
28 changes: 15 additions & 13 deletions lib/Mojolicious/Plugin/Mail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use constant FROM => 'test-mail-plugin@mojolicio.us';
use constant CHARSET => 'UTF-8';
use constant ENCODING => 'base64';

our $VERSION = '0.94';
our $VERSION = '0.95';

has conf => sub { +{} };

Expand All @@ -32,7 +32,7 @@ sub register {
# simple interface
unless (exists $args->{mail}) {
$args->{mail}->{ $_->[1] } = delete $args->{ $_->[0] }
for grep { $args->{ $_->[0] } }
for grep $args->{ $_->[0] },
[to => 'To' ], [from => 'From'], [reply_to => 'Reply-To'],
[cc => 'Cc' ], [bcc => 'Bcc' ], [subject => 'Subject' ],
[data => 'Data'], [type => 'Type'],
Expand All @@ -54,17 +54,17 @@ sub register {
my $test = $args->{test} || TEST;
$msg->send( $conf->{'how'}, @{$conf->{'howargs'}||[]} ) unless $test;

return $msg->as_string;
$msg->as_string;
},
);

$app->helper(
render_mail => sub {
my $self = shift;
my $data = $self->render_partial(@_, format => 'mail');
my $data = $self->render(@_, format => 'mail', partial => 1);

delete @{$self->stash}{ qw(partial mojo.content mojo.rendered format) };
return $data;
delete @{$self->stash}{ qw(partial cb format mojo.captures mojo.started mojo.content mojo.routed mojo.secret) };
$data;
},
);
}
Expand All @@ -82,19 +82,21 @@ sub build {

# tuning

$mail->{From} ||= $conf->{from};
$mail->{Type} ||= $conf->{type};
$mail->{From} ||= $conf->{from} || '';
$mail->{Type} ||= $conf->{type} || '';

if ($mail->{Data} && $mail->{Type} !~ /multipart/) {
$mail->{Encoding} ||= $encoding;
_enc($mail->{Data} => $charset);
}

if ($mimeword) {
$_ = MIME::EncWords::encode_mimeword($_, $encode, $charset) for grep { _enc($_ => $charset); 1 } $mail->{Subject};
$_ = MIME::EncWords::encode_mimeword($_, $encode, $charset)
for grep { _enc($_ => $charset); 1 } $mail->{Subject}
;

for (grep { $mail->{$_} } qw(From To Cc Bcc)) {
$mail->{$_} = join ",\n",
for (grep $mail->{$_}, qw(From To Cc Bcc)) {
$mail->{$_} = join ", ",
grep {
_enc($_ => $charset);
{
Expand Down Expand Up @@ -143,13 +145,13 @@ sub build {
@{$p->{attach} || []}
;

return $msg;
$msg;
}

sub _enc($$) {
my $charset = $_[1] || CHARSET;
$_[0] = b($_[0])->encode('UTF-8')->to_string if $_[0] && $charset && $charset =~ /utf-8/i;
return $_[0];
$_[0];
}

1;
Expand Down
22 changes: 12 additions & 10 deletions t/mail.t
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env perl
use lib qw(lib ../../lib);
use lib qw(lib ../lib ../mojo/lib ../../mojo/lib);
use utf8;

BEGIN { $ENV{MOJO_NO_BONJOUR}++ };
Expand All @@ -17,7 +17,7 @@ plugin mail => {

get '/empty' => sub {
my $self = shift;
$self->render_json({ ok => 1, mail => $self->mail || undef})
$self->render(json => { ok => 1, mail => $self->mail || undef})
};

get '/simple' => sub {
Expand All @@ -30,7 +30,7 @@ get '/simple' => sub {
data => "<p>Привет!</p>",
);

$self->render_json({ ok => 1, mail => $mail });
$self->render(json => { ok => 1, mail => $mail });
};

get '/simple1' => sub {
Expand All @@ -45,7 +45,7 @@ get '/simple1' => sub {
},
);

$self->render_json({ ok => 1, mail => $mail });
$self->render(json => { ok => 1, mail => $mail });
};

get '/simple2' => sub {
Expand All @@ -64,7 +64,7 @@ get '/simple2' => sub {
},
);

$self->render_json({ ok => 1, mail => $mail });
$self->render(json => { ok => 1, mail => $mail });
};

get '/attach' => sub {
Expand Down Expand Up @@ -93,7 +93,7 @@ get '/attach' => sub {
headers => [ { 'X-My-Header' => 'Mojolicious' }, { 'X-Mailer' => 'My mail client' } ],
);

$self->render_json({ ok => 1, mail => $mail });
$self->render(json => { ok => 1, mail => $mail });
};

get '/multi' => sub {
Expand Down Expand Up @@ -126,7 +126,7 @@ get '/multi' => sub {
],
);

$self->render_json({ ok => 1, mail => $mail });
$self->render(json => { ok => 1, mail => $mail });
};

get '/render' => sub {
Expand Down Expand Up @@ -231,7 +231,7 @@ get '/render_simple_reply_to_plain' => sub {

#

use Test::More tests => 178;
use Test::More;
use Test::Mojo;

use Mojo::Headers;
Expand All @@ -244,7 +244,7 @@ my $json;

$t->get_ok('/empty')
->status_is(200)
->json_content_is({ok => 1, mail => undef}, 'empty')
->json_is({ok => 1, mail => undef}, 'empty')
;

$json = $t->get_ok('/simple')
Expand Down Expand Up @@ -579,6 +579,8 @@ $d = $t->get_ok('/render_simple_reply_to_plain')
is $body, "CjxwPtCf0YDQuNCy0LXRgiBtYWlsIHJlbmRlcjIhPC9wPgo=\n", 'render_simple_reply_to_plain';
}

done_testing;

__DATA__
@@ render.html.ep
Expand All @@ -595,6 +597,6 @@ __DATA__
<p><%== $mail %></p>
@@ render2.mail.ep
% stash 'subject' => 'Привет render2';
% stash subject => 'Привет render2';
<p>Привет mail render2!</p>

0 comments on commit b69c0ba

Please sign in to comment.