Skip to content

Commit

Permalink
use Moo instead of Moose
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanez committed Dec 5, 2012
1 parent 784c743 commit 0a3ad8b
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 138 deletions.
5 changes: 4 additions & 1 deletion dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ remove = AutoPrereqs
[Prereqs]
; NON-CORE PREREQUISITES
Capture::Tiny = 0.08 ; for testing
Class::Load = 0.20
Email::Abstract = 3 ; XXX: really use Abstract?; 3 = \$str
Email::Address = 0 ; used for env-from-msg (::Simple)
List::MoreUtils = 0 ; minimum version unknown; uniq
Moose = 0.70 ; based on feedback from ANDK looking at testers
Moo = 1.000001
Moo::Role = 0
MooX::Types::MooseLike::Base = 0
Net::SMTP = 0 ;
Try::Tiny = 0 ; required by Moose, anyway
Throwable::Error = 0.100090 ; with $obj->throw and ->throw($str)
Expand Down
6 changes: 3 additions & 3 deletions lib/Email/Sender.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Email::Sender;
use Moose::Role;
use Moo::Role;
# ABSTRACT: a library for sending email

requires 'send';
Expand Down Expand Up @@ -44,7 +44,7 @@ start with L<Email::Sender::Manual::QuickStart>.
=head1 IMPLEMENTING
Email::Sender itelf is a Moose role. Any class that implements Email::Sender
Email::Sender itelf is a Moo role. Any class that implements Email::Sender
is required to provide a method called C<send>. This method should accept any
input that can be understood by L<Email::Abstract>, followed by a hashref
containing C<to> and C<from> arguments to be used as the envelope. The method
Expand All @@ -53,5 +53,5 @@ L<Email::Sender::Failure> on failure.
=cut

no Moose::Role;
no Moo::Role;
1;
18 changes: 11 additions & 7 deletions lib/Email/Sender/Failure.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Email::Sender::Failure;
use Moose;
use Moo;
use MooX::Types::MooseLike::Base qw(ArrayRef);
extends 'Throwable::Error';
# ABSTRACT: a report of failure from an email sending transport

Expand All @@ -26,14 +27,18 @@ This returns a list of addresses to which the email could not be sent.
=cut

has recipients => (
isa => 'ArrayRef',
traits => [ 'Array' ],
handles => { __recipients => 'elements' },
isa => ArrayRef,
default => sub { [] },
writer => '_set_recipients',
reader => '__get_recipients',
is => 'ro',
);

sub __recipients {
my ($self) = @_;
return @{$self->{recipients}};
}

sub recipients {
my ($self) = @_;
return $self->__recipients if wantarray;
Expand All @@ -57,7 +62,7 @@ be used as the C<message> of the new failure.

sub BUILD {
my ($self) = @_;
confess("message must contain non-space characters")
Carp::confess("message must contain non-space characters")
unless $self->message =~ /\S/;
}

Expand All @@ -75,6 +80,5 @@ sub BUILD {
=cut

__PACKAGE__->meta->make_immutable(inline_constructor => 0);
no Moose;
no Moo;
1;
15 changes: 9 additions & 6 deletions lib/Email/Sender/Failure/Multi.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Email::Sender::Failure::Multi;
use Moose;
use Moo;
use MooX::Types::MooseLike::Base qw(ArrayRef);
extends 'Email::Sender::Failure';
# ABSTRACT: an aggregate of multiple failures

Expand All @@ -16,13 +17,16 @@ by this multi.
=cut

has failures => (
isa => 'ArrayRef',
traits => [ 'Array' ],
handles => { __failures => 'elements' },
is => 'ro',
isa => ArrayRef,
required => 1,
reader => '__get_failures',
);

sub __failures {
@{$_[0]->__get_failures};
}

sub failures {
my ($self) = @_;
return $self->__failures if wantarray;
Expand Down Expand Up @@ -65,6 +69,5 @@ sub isa {
return $self->SUPER::isa($class);
}

__PACKAGE__->meta->make_immutable(inline_constructor => 0);
no Moose;
no Moo;
1;
5 changes: 2 additions & 3 deletions lib/Email/Sender/Failure/Permanent.pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package Email::Sender::Failure::Permanent;
use Moose;
use Moo;
extends 'Email::Sender::Failure';
# ABSTRACT: a permanent delivery failure

__PACKAGE__->meta->make_immutable(inline_constructor => 0);
no Moose;
no Moo;
1;
5 changes: 2 additions & 3 deletions lib/Email/Sender/Failure/Temporary.pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package Email::Sender::Failure::Temporary;
use Moose;
use Moo;
extends 'Email::Sender::Failure';
# ABSTRACT: a temporary delivery failure

__PACKAGE__->meta->make_immutable(inline_constructor => 0);
no Moose;
no Moo;
1;
10 changes: 5 additions & 5 deletions lib/Email/Sender/Role/CommonSending.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Email::Sender::Role::CommonSending;
use Moose::Role;
use Moo::Role;
# ABSTRACT: the common sending tasks most Email::Sender classes will need

use Carp;
Expand Down Expand Up @@ -43,7 +43,7 @@ sub send {
try {
return $self->send_email($email, $envelope, @rest);
} catch {
confess('unknown error') unless my $err = $_;
Carp::confess('unknown error') unless my $err = $_;

if (
try { $err->isa('Email::Sender::Failure') }
Expand All @@ -66,13 +66,13 @@ object. You probably shouldn't override it in most cases.
sub prepare_email {
my ($self, $msg) = @_;

confess("no email passed in to sender") unless defined $msg;
Carp::confess("no email passed in to sender") unless defined $msg;

# We check blessed because if someone would pass in a large message, in some
# perls calling isa on the string would create a package with the string as
# the name. If the message was (say) two megs, now you'd have a two meg hash
# key in the stash. Oops! -- rjbs, 2008-12-04
return $msg if blessed $msg and eval { $msg->isa('Email::Abstract') };
return $msg if Scalar::Util::blessed $msg and eval { $msg->isa('Email::Abstract') };

return Email::Abstract->new($msg);
}
Expand Down Expand Up @@ -111,5 +111,5 @@ sub success {
my $success = Email::Sender::Success->new(@_);
}

no Moose::Role;
no Moo::Role;
1;
4 changes: 2 additions & 2 deletions lib/Email/Sender/Role/HasMessage.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Email::Sender::Role::HasMessage;
use Moose::Role;
use Moo::Role;
# ABSTRACT: an object that has a message

=attr message
Expand All @@ -13,5 +13,5 @@ has message => (
required => 1,
);

no Moose::Role;
no Moo::Role;
1;
9 changes: 5 additions & 4 deletions lib/Email/Sender/Simple.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Email::Sender::Simple;
use Moose;
use Moo;
with 'Email::Sender::Role::CommonSending';
# ABSTRACT: the simple interface for sending mail with Sender

Expand All @@ -21,6 +21,7 @@ use Sub::Exporter -setup => {
use Email::Address;
use Email::Sender::Transport;
use Try::Tiny;
use Class::Load ();

{
my $DEFAULT_TRANSPORT;
Expand All @@ -43,7 +44,7 @@ use Try::Tiny;
$transport_class = "Email::Sender::Transport::$transport_class";
}

Class::MOP::load_class($transport_class);
Class::Load::load_class($transport_class);

my %arg;
for my $key (grep { /^EMAIL_SENDER_TRANSPORT_\w+/ } keys %ENV) {
Expand Down Expand Up @@ -102,7 +103,7 @@ sub send_email {
$transport = delete $arg->{transport} unless $self->_default_was_from_env;
}

confess("transport $transport not safe for use with Email::Sender::Simple")
Carp::confess("transport $transport not safe for use with Email::Sender::Simple")
unless $transport->is_simple;

my ($to, $from) = $self->_get_to_from($email, $arg);
Expand Down Expand Up @@ -158,5 +159,5 @@ sub _get_to_from {
return ($to, $from);
}

no Moose;
no Moo;
"220 OK";
5 changes: 2 additions & 3 deletions lib/Email/Sender/Success.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Email::Sender::Success;
use Moose;
use Moo;
# ABSTRACT: the result of successfully sending mail

=head1 DESCRIPTION
Expand All @@ -9,6 +9,5 @@ successfully sent. Unless extended, it has no properties of its own.
=cut

__PACKAGE__->meta->make_immutable;
no Moose;
no Moo;
1;
7 changes: 3 additions & 4 deletions lib/Email/Sender/Success/Partial.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Email::Sender::Success::Partial;
use Moose;
use Moo;
extends 'Email::Sender::Success';
# ABSTRACT: a report of partial success when delivering

Expand All @@ -15,10 +15,9 @@ use Email::Sender::Failure::Multi;

has failure => (
is => 'ro',
isa => 'Email::Sender::Failure::Multi',
isa => sub { 'Email::Sender::Failure::Multi' },
required => 1,
);

__PACKAGE__->meta->make_immutable;
no Moose;
no Moo;
1;
6 changes: 3 additions & 3 deletions lib/Email/Sender/Transport.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package Email::Sender::Transport;
use Moose::Role;
use Moo::Role;
# ABSTRACT: a role for email transports

=head1 DESCRIPTION
Email::Sender::Transport is a Moose role to aid in writing classes used to send
Email::Sender::Transport is a Moo role to aid in writing classes used to send
mail. For the most part, its behavior comes entirely from the role
L<Email::Sender::Role::CommonSending>, which it includes. The important
difference is that Transports are often intended to be used by
Expand Down Expand Up @@ -36,5 +36,5 @@ sub is_simple {

sub allow_partial_success { 0 }

no Moose::Role;
no Moo::Role;
1;
5 changes: 2 additions & 3 deletions lib/Email/Sender/Transport/DevNull.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Email::Sender::Transport::DevNull;
use Moose;
use Moo;
with 'Email::Sender::Transport';
# ABSTRACT: happily throw away your mail

Expand All @@ -12,6 +12,5 @@ DevNull transport will be silently discarded.

sub send_email { return $_[0]->success }

__PACKAGE__->meta->make_immutable;
no Moose;
no Moo;
1;
28 changes: 18 additions & 10 deletions lib/Email/Sender/Transport/Failable.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Email::Sender::Transport::Failable;
use Moose;
use Moo;
use MooX::Types::MooseLike::Base qw(ArrayRef);
extends 'Email::Sender::Transport::Wrapper';
# ABSTRACT: a wrapper to makes things fail predictably

Expand All @@ -21,16 +22,24 @@ If any coderef returns a true value, the value will be used to signal failure.
=cut

has 'failure_conditions' => (
isa => 'ArrayRef',
isa => ArrayRef,
default => sub { [] },
traits => [ 'Array' ],
handles => {
failure_conditions => 'elements',
clear_failure_conditions => 'clear',
fail_if => 'push',
},
is => 'ro',
reader => '_failure_conditions',
);

sub failure_conditions {
@{$_[0]->_failure_conditions};
}

sub fail_if {
push @{shift->_failure_conditions}, @_;
}

sub clear_failure_conditions {
$_[0]->{failure_conditions} = [];
}

around send_email => sub {
my ($orig, $self, $email, $env, @rest) = @_;

Expand All @@ -43,6 +52,5 @@ around send_email => sub {
return $self->$orig($email, $env, @rest);
};

__PACKAGE__->meta->make_immutable;
no Moose;
no Moo;
1;
Loading

0 comments on commit 0a3ad8b

Please sign in to comment.