aboutsummaryrefslogtreecommitdiff
path: root/lib/Sietima/Subscriber.pm
blob: e25f8c6cc308d0f074944562097545750cd38f7d (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package Sietima::Subscriber; 
use Moo;
use Sietima::Policy;
use Types::Standard qw(ArrayRef HashRef Object);
use Type::Params -sigs;
use Sietima::Types qw(Address AddressFromStr);
use Email::Address;
use List::AllUtils qw(any);
use namespace::clean;
 
our $VERSION = '1.1.2'# VERSION 
# ABSTRACT: a subscriber to a mailing list 
 
 
has primary => (
    isa => Address,
    is => 'ro',
    required => 1,
    coerce => AddressFromStr,
    handles => [qw(address name original)],
);
 
 
my $address_array = ArrayRef[
    Address->plus_coercions(
        AddressFromStr
    )
];
has aliases => (
    isa => $address_array,
    is => 'lazy',
    coerce => $address_array->coercion,
);
sub _build_aliases { +[] }
 
 
has prefs => (
    isa => HashRef,
    is => 'ro',
    default => sub { +{} },
);
 
 
signature_for match => (
    method => Object,
    positional => [ Address->plus_coercions(AddressFromStr) ],
);
sub match($self,$addr) {
    return any { $addr->address eq $_->address }
        $self->primary, $self->aliases->@*;
}
 
 
1;
 
__END__
 
=pod
 
=encoding UTF-8
 
=head1 NAME
 
Sietima::Subscriber - a subscriber to a mailing list
 
=head1 VERSION
 
version 1.1.2
 
=head1 DESCRIPTION
 
This class holds the primary email address for a mailing list
subscriber, together with possible aliases and preferences.
 
=head1 ATTRIBUTES
 
All attributes are read-only.
 
=head2 C<primary>
 
Required L<< C<Email::Address> >> object, coercible from a string.
 
This is the primary address for the subscriber, the one where they
will receive messages from the mailing list.
 
=head2 C<aliases>
 
Arrayref of L<< C<Email::Address> >> objects, each coercible from a
string. Defaults to an empty arrayref.
 
These are secondary addresses that the subscriber may write
from. Subscriber-only mailing lists should accept messages from any of
these addresses as if they were from the primary. The L<< /C<match> >>
simplifies that task.
 
=head2 C<prefs>
 
A hashref. Various preferences that may be interpreted by Sietima
roles. Defaults to an empty hashref.
 
=head1 METHODS
 
=head2 C<match>
 
  if ($subscriber->match($address)) { ... }
 
Given a L<< C<Email::Address> >> object (or a string), this method
returns true if the address is equivalent to the
L</primary> or any of the L</aliases>.
 
This method should be used to determine whether an address belongs to
a subscriber.
 
=head2 C<address>
 
=head2 C<name>
 
=head2 C<original>
 
These methods delegate to L<< C<Email::Address> >>'s methods of the
same name, invoked on the L<primary address|/primary>.
 
=head1 AUTHOR
 
Gianni Ceccarelli <dakkar@thenautilus.net>
 
=head1 COPYRIGHT AND LICENSE
 
This software is copyright (c) 2023 by Gianni Ceccarelli <dakkar@thenautilus.net>.
 
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
 
=cut