File Coverage

blib/lib/Sietima/Message.pm
Criterion Covered Total %
statement 30 30 100.0
branch 2 4 50.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 42 44 95.4


line stmt bran cond sub pod time code
1             package Sietima::Message;
2 16     16   122 use Moo;
  16         44  
  16         156  
3 16     16   6873 use Sietima::Policy;
  16         47  
  16         146  
4 16     16   124 use Types::Standard qw(ArrayRef Object);
  16         41  
  16         139  
5 16         116 use Sietima::Types qw(Address AddressFromStr
6             Subscriber SubscriberFromAddress SubscriberFromStr
7 16     16   15854 EmailMIME);
  16         252  
8 16     16   18825 use Email::Address;
  16         46  
  16         425  
9 16     16   6991 use Sietima::Subscriber;
  16         72  
  16         633  
10 16     16   147 use Email::MIME;
  16         46  
  16         370  
11 16     16   92 use namespace::clean;
  16         41  
  16         160  
12              
13             our $VERSION = '1.0.3'; # VERSION
14             # ABSTRACT: an email message with an envelope
15              
16              
17             has mail => (
18             is => 'ro',
19             isa => EmailMIME,
20             required => 1,
21             );
22              
23              
24             has from => (
25             is => 'ro',
26             isa => Address,
27             coerce => AddressFromStr,
28             required => 1,
29             );
30              
31              
32             my $subscriber_array = ArrayRef[
33             Subscriber->plus_coercions(
34             SubscriberFromStr,
35             SubscriberFromAddress,
36             )
37             ];
38             has to => (
39             isa => $subscriber_array,
40             is => 'ro',
41             coerce => $subscriber_array->coercion,
42             required => 1,
43             );
44              
45              
46 25 50   25 1 203 sub envelope ($self) {
  25 50       99  
  25         62  
  25         57  
47             return {
48             from => $self->from,
49 25         165 to => [ map { $_->address } $self->to->@* ],
  41         1519  
50             }
51             }
52              
53             1;
54              
55             __END__
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =head1 NAME
62              
63             Sietima::Message - an email message with an envelope
64              
65             =head1 VERSION
66              
67             version 1.0.3
68              
69             =head1 SYNOPSIS
70              
71             use Sietima::Message;
72              
73             my $msg = Sietima::Message->new({
74             mail => $email_mime_object,
75             from => 'sender@example.com',
76             to => [ 'recipient@example.com', 'also@example.com' ],
77             });
78              
79             =head1 DESCRIPTION
80              
81             This class pairs a L<< C<Email::MIME> >> object with its
82             envelope. Objects of this class are usually generated by L<<
83             C<Sietima::munge_mail>|Sietima/munge_mail >>, and consumed by L<<
84             C<Sietima::send_message>|Sietima/send_message >>.
85              
86             =head1 ATTRIBUTES
87              
88             All attributes are read-only and required.
89              
90             =head2 C<mail>
91              
92             An L<< C<Email::MIME> >> object, representing the message.
93              
94             =head2 C<from>
95              
96             An L<< C<Email::Address> >> object, coercible from a string,
97             representing the sender.
98              
99             =head2 C<to>
100              
101             An arrayref of L<< C<Sietima::Subscriber> >> objects, each coercible
102             from a string or an L<< C<Email::Address> >> object, representing the
103             recipients.
104              
105             =head1 METHODS
106              
107             =head2 C<envelope>
108              
109             my %envelope = $message->envelope->%*;
110              
111             Returns a hashref with envelope data, suitable for use with L<<
112             C<Email::Sender::Transport::send>|Email::Sender::Transport/send >>.
113              
114             =head1 AUTHOR
115              
116             Gianni Ceccarelli <dakkar@thenautilus.net>
117              
118             =head1 COPYRIGHT AND LICENSE
119              
120             This software is copyright (c) 2017 by Gianni Ceccarelli <dakkar@thenautilus.net>.
121              
122             This is free software; you can redistribute it and/or modify it under
123             the same terms as the Perl 5 programming language system itself.
124              
125             =cut