diff options
author | Julian Blake Kongslie <jblake@omgwallhack.org> | 2010-03-17 22:47:35 -0700 |
---|---|---|
committer | Julian Blake Kongslie <jblake@omgwallhack.org> | 2010-03-17 22:47:35 -0700 |
commit | 654a7353e1c46878dd84bfef0e987f0205e03fde (patch) | |
tree | 1d50d4ae0fad99f874fc85673907c9beb8d133fb /usr/src/libpiny/Piny/Email.pm | |
parent | 225cfa610fc07cb143f5a86c06f87829f9e240d2 (diff) | |
download | piny-code-654a7353e1c46878dd84bfef0e987f0205e03fde.tar.gz piny-code-654a7353e1c46878dd84bfef0e987f0205e03fde.zip |
Initial version of the libpiny stuff.
Diffstat (limited to 'usr/src/libpiny/Piny/Email.pm')
-rw-r--r-- | usr/src/libpiny/Piny/Email.pm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/usr/src/libpiny/Piny/Email.pm b/usr/src/libpiny/Piny/Email.pm new file mode 100644 index 0000000..c6c3d96 --- /dev/null +++ b/usr/src/libpiny/Piny/Email.pm @@ -0,0 +1,42 @@ +package Piny::Email; + +use Moose; +use Moose::Util::TypeConstraints; + +use Email::Valid::Loose; + +# Types + +my $checker = Email::Valid::Loose->new("-fqdn" => 1, "-fudge" => 0, "-local_rules" => 0, "-mxcheck" => 1, "-tldcheck" => 0 ); + +subtype 'EmailAddress' + => as 'Str' + => where { $checker->address( $_ ) } + => message { 'That does not appear to be a valid email address.' } + ; + +# Attributes + +has 'address' => + ( is => 'rw' + , isa => 'EmailAddress' + ); + +# Builder methods + +# If constructed with just one argument, then treat it as an address. +around BUILDARGS => sub { + my ( $orig, $class ) = ( shift, shift ); + + if ( @_ == 1 && ! ref $_[0] ) { + return $class->$orig( address => $_[0] ); + } else { + return $class->$orig( @_ ); + }; +}; + +# Moose boilerplate + +__PACKAGE__->meta->make_immutable; + +1; |