aboutsummaryrefslogtreecommitdiff
path: root/lib/Sietima/Types.pm
blob: af650b93cfde492457ca3571f54932044577e69e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package Sietima::Types; 
use 5.024;
use strict;
use warnings;
use Type::Utils -all;
use Types::Standard qw(Str HashRef);
use namespace::clean;
use Type::Library
    -base,
    -declare => qw(Address AddressFromStr
                   EmailMIME Message
                   Subscriber SubscriberFromAddress SubscriberFromStr SubscriberFromHashRef
                   Transport MailStore);
 
class_type EmailMIME, { class => 'Email::MIME' };
role_type Transport, { role => 'Email::Sender::Transport' };
role_type MailStore, { role => 'Sietima::MailStore' };
 
class_type Address, { class => 'Email::Address' };
declare_coercion AddressFromStr,
    to_type Address, from Str,
    q{ (Email::Address->parse($_))[0] };
 
class_type Message, { class => 'Sietima::Message' };
 
class_type Subscriber, { class => 'Sietima::Subscriber' };
declare_coercion SubscriberFromAddress,
    to_type Subscriber, from Address,
    q{ Sietima::Subscriber->new(raw_address=>$_) };
declare_coercion SubscriberFromStr,
    to_type Subscriber, from Str,
    q{ Sietima::Subscriber->new(raw_address=>(Email::Address->parse($_))[0]) };
 
declare_coercion SubscriberFromHashRef,
    to_type Subscriber, from HashRef,
    q{ my $a = delete $_->{address};Sietima::Subscriber->new({raw_address => $a, prefs => $_ }};
 
1;