package Sietima::Role::NoMail; use Moo::Role; use Sietima::Policy; use namespace::clean; # VERSION # ABSTRACT: don't send mail to those who don't want it =head1 SYNOPSIS my $sietima = Sietima->with_traits('NoMail')->new({ %args, subscribers => [ { primary => 'write-only@example.com', prefs => { wants_mail => 0 } }, @other_subscribers, ], }); =head1 DESCRIPTION A L<< C >> list with this role applied will not send messages to subscribers that have the C preference set to a false value. =modif C Filters out subscribers that have the C preference set to a false value. =cut around subscribers_to_send_to => sub ($orig,$self,$mail) { return [ grep { $_->prefs->{wants_mail} // 1 } $self->$orig($mail)->@*, ]; }; 1;