MooseX::Types::Email - Email address validation type constraint for Moose.


MooseX-Types-Email documentation Contained in the MooseX-Types-Email distribution.

Index


Code Index:

NAME

Top

MooseX::Types::Email - Email address validation type constraint for Moose.

SYNOPSIS

Top

    package MyClass;
    use Moose;
    use MooseX::Types::Email qw/EmailAddress EmailMessage/;
    use namespace::autoclean;

    has email => ( isa => EmailAddress, required => 1, is => 'ro' );
    has message => ( isa => EmailMessage, required => 1, is => 'ro' );

DESCRIPTION

Top

Moose type constraints which uses Email::Valid and Email::Abstract to check for valid email addresses and messages.

Note that EmailMessage must be an object that can be passed to Email::Abstract. Currently, constraining strings is not supported due to the leniency of Email::Abstract.

SEE ALSO

Top

Moose::Util::TypeConstraints
MooseX::Types
Email::Valid
Email::Abstract

AUTHORS

Top

Tomas Doran (t0m) <bobtfish@bobtfish.net>

Shamelessly extracted from Reaction::Types::Email.

CONTRIBUTORS

Top

Chris Nehren <apeiron@cpan.org> added support for validing email messages.

COPYRIGHT

Top

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


MooseX-Types-Email documentation Contained in the MooseX-Types-Email distribution.

package MooseX::Types::Email;
use MooseX::Types
    -declare => [qw/EmailAddress EmailMessage/];

use MooseX::Types::Moose qw/Object/;
use MooseX::Types::Common::String 'NonEmptySimpleStr';
use Email::Valid;
use Email::Abstract;

our $VERSION = '0.004';

subtype EmailAddress,
  as NonEmptySimpleStr,
  where { Email::Valid->address($_) },
  message { "Must be a valid e-mail address" };

subtype EmailMessage,
  as Object, where { Email::Abstract->new($_) },
  message { "Must be something Email::Abstract recognizes" };

coerce EmailMessage,
  from Object,
  via { Email::Abstract->new($_) };
1;