The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooX::Types::MooseLike::Email - Email address validation type constraint for Moo.

SYNOPSIS

  package MyClass;
  use Moo;
  use MooX::Types::MooseLike::Email qw/:all/;

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

DESCRIPTION

MooX::Types::MooseLike::Email is Moo type constraints which uses Email::Valid, Email::Valid::Loose and Email::Abstract to check for valid email addresses and messages.

TYPES

EmailAddress

An email address

EmailAddressLoose

An email address, which allows . (dot) before @ (at-mark)

EmailMessage

An object, which is a Mail::Internet, MIME::Entity, Mail::Message, Email::Simple or Email::MIME

TIPS

  • coerce the attribute

      use Scalar::Util qw(blessed);
    
      has 'message' => (
          is       => 'ro',
          isa      => EmailMessage,
          required => 1,
          coerce   => sub {
              return ( $_[0] and blessed( $_[0] ) and blessed( $_[0] ) ne 'Regexp' )
                  ? $_[0]
                  : Email::Simple->new( $_[0] );
          },
      );

AUTHOR

hayajo <hayajo@cpan.org>

SEE ALSO

MooX::Types::MooseLike, MooseX::Types::Email, MooseX::Types::Email::Loose

LICENSE

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