package Sietima::Types;
use Sietima::Policy;
use Type::Utils -all;
use Types::Standard qw(Str HashRef Defined Str);
use namespace::clean;
use Type::Library
-base,
-declare => qw(SietimaObj
Address AddressFromStr
TagName
EmailMIME Message
HeaderUri HeaderUriFromThings
Subscriber SubscriberFromAddress SubscriberFromStr SubscriberFromHashRef
Transport MailStore MailStoreFromHashRef);
class_type SietimaObj, { class => 'Sietima' };
class_type EmailMIME, { class => 'Email::MIME' };
role_type Transport, { role => 'Email::Sender::Transport' };
role_type MailStore, { role => 'Sietima::MailStore' };
declare_coercion MailStoreFromHashRef,
to_type MailStore, from HashRef,
q{ require Module::Runtime; } .
q{ Module::Runtime::use_module(delete $_->{class})->new($_); };
class_type Address, { class => 'Email::Address' };
declare_coercion AddressFromStr,
to_type Address, from Str,
q{ (Email::Address->parse($_))[0] };
declare TagName, as Str,
where { /\A\w+\z/ },
inline_as sub($constraint,$varname,@){
$constraint->parent->inline_check($varname)
.qq{ && ($varname =~/\\A\\w+\\z/) };
};
class_type Message, { class => 'Sietima::Message' };
class_type HeaderUri, { class => 'Sietima::HeaderURI' };
declare_coercion HeaderUriFromThings,
to_type HeaderUri, from Defined,
q{ Sietima::HeaderURI->new($_) };
class_type Subscriber, { class => 'Sietima::Subscriber' };
declare_coercion SubscriberFromAddress,
to_type Subscriber, from Address,
q{ Sietima::Subscriber->new(primary=>$_) };
declare_coercion SubscriberFromStr,
to_type Subscriber, from Str,
q{ Sietima::Subscriber->new(primary=>(Email::Address->parse($_))[0]) };
declare_coercion SubscriberFromHashRef,
to_type Subscriber, from HashRef,
q{ Sietima::Subscriber->new($_) };
1;