File Coverage

blib/lib/Sietima/Subscriber.pm
Criterion Covered Total %
statement 29 29 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 41 41 100.0


line stmt bran cond sub pod time code
1             package Sietima::Subscriber;
2 16     16   93 use Moo;
  16         27  
  16         77  
3 16     16   3753 use Sietima::Policy;
  16         31  
  16         70  
4 16     16   76 use Types::Standard qw(ArrayRef HashRef Object);
  16         28  
  16         71  
5 16     16   12112 use Type::Params qw(compile);
  16         32  
  16         79  
6 16     16   2866 use Sietima::Types qw(Address AddressFromStr);
  16         25  
  16         75  
7 16     16   6895 use Email::Address;
  16         28  
  16         302  
8 16     16   7040 use List::AllUtils qw(any);
  16         137202  
  16         1152  
9 16     16   115 use namespace::clean;
  16         30  
  16         185  
10              
11             our $VERSION = '1.0.5'; # VERSION
12             # ABSTRACT: a subscriber to a mailing list
13              
14              
15             has primary => (
16             isa => Address,
17             is => 'ro',
18             required => 1,
19             coerce => AddressFromStr,
20             handles => [qw(address name original)],
21             );
22              
23              
24             my $address_array = ArrayRef[
25             Address->plus_coercions(
26             AddressFromStr
27             )
28             ];
29             has aliases => (
30             isa => $address_array,
31             is => 'lazy',
32             coerce => $address_array->coercion,
33             );
34 7     7   211 sub _build_aliases { +[] }
35              
36              
37             has prefs => (
38             isa => HashRef,
39             is => 'ro',
40             default => sub { +{} },
41             );
42              
43              
44             sub match {
45             # we can't use the sub signature here, because we need the
46             # coercion
47 17     17 1 1039 state $check = compile(Object,Address->plus_coercions(AddressFromStr));
48 17         6704 my ($self,$addr) = $check->(@_);
49              
50 22     22   315 return any { $addr->address eq $_->address }
51 17         840 $self->primary, $self->aliases->@*;
52             }
53              
54              
55             1;
56              
57             __END__
58              
59             =pod
60              
61             =encoding UTF-8
62              
63             =head1 NAME
64              
65             Sietima::Subscriber - a subscriber to a mailing list
66              
67             =head1 VERSION
68              
69             version 1.0.5
70              
71             =head1 DESCRIPTION
72              
73             This class holds the primary email address for a mailing list
74             subscriber, together with possible aliases and preferences.
75              
76             =head1 ATTRIBUTES
77              
78             All attributes are read-only.
79              
80             =head2 C<primary>
81              
82             Required L<< C<Email::Address> >> object, coercible from a string.
83              
84             This is the primary address for the subscriber, the one where they
85             will receive messages from the mailing list.
86              
87             =head2 C<aliases>
88              
89             Arrayref of L<< C<Email::Address> >> objects, each coercible from a
90             string. Defaults to an empty arrayref.
91              
92             These are secondary addresses that the subscriber may write
93             from. Subscriber-only mailing lists should accept messages from any of
94             these addresses as if they were from the primary. The L<< /C<match> >>
95             simplifies that task.
96              
97             =head2 C<prefs>
98              
99             A hashref. Various preferences that may be interpreted by Sietima
100             roles. Defaults to an empty hashref.
101              
102             =head1 METHODS
103              
104             =head2 C<match>
105              
106             if ($subscriber->match($address)) { ... }
107              
108             Given a L<< C<Email::Address> >> object (or a string), this method
109             returns true if the address is equivalent to the
110             L</primary> or any of the L</aliases>.
111              
112             This method should be used to determine whether an address belongs to
113             a subscriber.
114              
115             =head2 C<address>
116              
117             =head2 C<name>
118              
119             =head2 C<original>
120              
121             These methods delegate to L<< C<Email::Address> >>'s methods of the
122             same name, invoked on the L<primary address|/primary>.
123              
124             =head1 AUTHOR
125              
126             Gianni Ceccarelli <dakkar@thenautilus.net>
127              
128             =head1 COPYRIGHT AND LICENSE
129              
130             This software is copyright (c) 2017 by Gianni Ceccarelli <dakkar@thenautilus.net>.
131              
132             This is free software; you can redistribute it and/or modify it under
133             the same terms as the Perl 5 programming language system itself.
134              
135             =cut