Subject: | Email::Send::Test enhancements |
http://search.cpan.org/~rjbs/Email-Send-2.185/lib/Email/Send/Test.pm#SYNOPSIS
Show quoted text
> SYNOPSIS
> ...
> isa_ok( $emails[0], 'Email::MIME' );
Shouldn't that be 'Email::Simple'?
http://search.cpan.org/src/RJBS/Email-Send-2.185/lib/Email/Send/Test.pm
Show quoted text> ...
> sub send {
> my $class = shift;
> push @EMAILS, @_;
> return 1;
> }
Wouldn't that make more sense as:
push @EMAILS, [@_];
Also, instead of:
return 1;
it should:
return $class->return_value;
or something like that, where return_value is a Class::Data::Inheritable
accessor or the like.
Below is the test driver class I ended up using.
# a mock mailer driver for Email::Send package
# (An enhanced version of Email::Send::Test)
package Email::Send::Test;
use base qw(Class::Data::Inheritable);
use Return::Value;
sub is_available {1}
__PACKAGE__->mk_classdata('calls' => []);
sub emails {
my $class = shift;
wantarray ? @{$class->calls} : scalar(@{$class->calls});
}
sub clear {
my $class = shift;
$class->calls([]);
}
__PACKAGE__->mk_classdata('return_value' => success() );
sub send {
my $class = shift;
push @{$class->calls}, [@_];
return $class->return_value;
}
It's used the same as Email::Send::Test. To create a variation that
returns a failure result code, you'd subclass it like:
# a mock mailer driver for Email::Send package that always fails
{
package My::Local::Namespace::mailerFail;
use base 'Email::Send::Test';
use Return::Value;
__PACKAGE__->return_value(failure());
}
# make 'require' in Email::Send happy
$INC{'My/Local/Namespace/mailerFail.pm'} = 1;
-Tom