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); # VERSION # ABSTRACT: type library for Sietima =head1 DESCRIPTION This module is a L<< C >>. It declares a few type constraints nad coercions. =type C An instance of L<< C >>. =cut class_type SietimaObj, { class => 'Sietima' }; =type C An instance of L<< C >>. =cut class_type EmailMIME, { class => 'Email::MIME' }; =type C An object that consumes the role L<< C >>. =cut role_type Transport, { role => 'Email::Sender::Transport' }; =type C An object that consumes the role L<< C >>. Coercions: =over =item C has store => ( isa => MailStore->plus_coercions(MailStoreFromHashRef) ); Using this coercion, a hashref of the form: { class => 'Some::Store::Class', %constructor_args, } will be converted into an instance of C built with the C<%constructor_args>. =back =cut 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($_); }; =type C
An instance of L<< C >>. Coercions: =over =item C has address => ( isa => Address->plus_coercions(AddressFromStr) ); Using this coercion, a string will be parsed into an L<< C >>. If the string contains more than one address, only the first one will be used. =back =cut class_type Address, { class => 'Email::Address' }; declare_coercion AddressFromStr, to_type Address, from Str, q{ (Email::Address->parse($_))[0] }; =type C A string composed exclusively of "word" (C) characters. Used by L to tag messages. =cut declare TagName, as Str, where { /\A\w+\z/ }, inline_as sub($constraint,$varname,@){ $constraint->parent->inline_check($varname) .qq{ && ($varname =~/\\A\\w+\\z/) }; }; =type C An instance of L<< C >>. =cut class_type Message, { class => 'Sietima::Message' }; class_type HeaderUri, { class => 'Sietima::HeaderURI' }; declare_coercion HeaderUriFromThings, to_type HeaderUri, from Defined, q{ Sietima::HeaderURI->new($_) }; =type C An instance of L<< C >>. Coercions: =over =item C has sub => ( isa => Subscriber->plus_coercions(SubscriberFromAddress) ); Using this coercion, an L<< C >> will be converted into a subscriber that has that address as its primary. =item C has sub => ( isa => Subscriber->plus_coercions(SubscriberFromStr) ); Using this coercion, a string will be converted into a subscriber that has the first address parsed from that string as its primary. =item C has sub => ( isa => Subscriber->plus_coercions(SubscriberFromHashRef) ); Using this coercion, a hashref will be converted into a subscriber by passing it to the constructor. =back =cut 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;