package Sietima::Subscriber;
use Moo;
use Sietima::Policy;
use Types::Standard qw(ArrayRef HashRef Object);
use Type::Params qw(compile);
use Sietima::Types qw(Address AddressFromStr);
use Email::Address;
use List::AllUtils qw(any);
use namespace::clean;
our $VERSION = '1.0.1'; # 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 { +{} },
);
sub match {
# we can't use the sub signature here, because we need the
# coercion
state $check = compile(Object,Address->plus_coercions(AddressFromStr));
my ($self,$addr) = $check->(@_);
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.0.1
=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