package Foo::Types::Library;
use Data::Dumper;
use MooseX::Types -declare => [
qw/
GooglePrimaryEmail
WWWGoogleContactsTypeEmail
/
];
use MooseX::Types::Email qw/EmailAddress/;
# WWWGoogleContactsTypeEmail
class_type WWWGoogleContactsTypeEmail, {
class => 'WWW::Google::Contacts::Type::Email',
};
# GooglePrimaryEmail
subtype GooglePrimaryEmail,
as EmailAddress,
message {
'validation failed for: '. Dumper $_;
};
coerce GooglePrimaryEmail,
from ArrayRef[WWWGoogleContactsTypeEmail],
via {
my $p = (grep { $_->{primary} } @$_)[0];
$p = $p ? $p->{value} : @$_->[0]{value};
return $p;
};
####
use MooseX::Declare;
class Foo {
use Foo::Types::Library qw /GooglePrimaryEmail/;
has 'email' => (
is => 'rw',
isa => GooglePrimaryEmail,
coerce => 1
);
}
####
use MooseX::Declare;
class Foo {
use Foo::Types::Library qw /Maybe[GooglePrimaryEmail]/;
has 'email' => (
is => 'rw',
isa => 'Maybe[GooglePrimaryEmail]',
coerce => 1
);
}