From 951a85d25ff25d2f4924a5ce35ce1272000fa017 Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 2 Jan 2017 17:43:00 +0000 Subject: documentation for the base class --- lib/Sietima.pm | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 207 insertions(+), 5 deletions(-) (limited to 'lib/Sietima.pm') diff --git a/lib/Sietima.pm b/lib/Sietima.pm index 94e082e..fb74bcc 100644 --- a/lib/Sietima.pm +++ b/lib/Sietima.pm @@ -16,6 +16,91 @@ use namespace::clean; with 'MooX::Traits'; +=head1 NAME + +Sietima - minimal mailing list manager + +=head1 SYNOPSIS + + use Sietima; + + Sietima->new({ + return_path => 'the-list@the-domain.tld', + subscribers => [ 'person@some.were', @etc ], + })->handle_mail_from_stdin; + +=head1 DESCRIPTION + +Sietima is a minimal mailing list manager written in modern Perl. It +aims to be the spiritual successor of L. + +The base C class does very little: it just puts the email +message from C into a new envelope using L<< /C >> +as sender and all the L<< /C >> addresses as recipients, +and sends it. + +Additional behaviour is provided via traits / roles. This class +consumes L<< C >> to simplify composing roles: + + Sietima->with_traits(qw(AvoidDups NoMail))->new(\%args); + +These are the traits provided with the default distribution: + +=over + +=item L<< C|Sietima::Role::AvoidDups >> + +prevents the sender from receiving copies of their own messages + +=item L<< C|Sietima::Role::Debounce >> + +avoids mail-loops using a C header + +=item L<< C|Sietima::Role::Headers >> + +adds C headers to all outgoing messages + +=item L<< C|Sietima::Role::NoMail >> + +avoids sending messages to subscribers who don't want them + +=item L<< C|Sietima::Role::ReplyTo >> + +optionally sets the C header to the mailing list address + +=item L<< C|Sietima::Role::SubjectTag >> + +prepends a C<[tag]> to the subject header of outgoing messages that +aren't already tagged + +=item L<< C|Sietima::Role::SubscriberOnly::Drop >> + +silently drops all messages coming from addresses not subscribed to +the list + +=item L<< C|Sietima::Role::SubscriberOnly::Moderate >> + +holds messages coming from addresses not subscribed to the list for +moderation, and provides commands to manage the moderation queue + +=back + +The only "configuration mechanism" currently supported is to +initialise a C object in your driver script, passing all the +needed values to the constructor. L<< C >> is the +recommended way of doing that: it adds command-line parsing capability +to Sietima. + +=head1 ATTRIBUTES + +=head2 C + +A L<< C >> instance, coerced from string if +necessary. This is the address that Sietima will send messages +I. + +=cut + has return_path => ( isa => Address, is => 'ro', @@ -23,11 +108,21 @@ has return_path => ( coerce => AddressFromStr, ); -sub list_addresses($self) { - return +{ - return_path => $self->return_path, - }; -} +=head2 C + +An array-ref of L<< C >> objects, defaults to the +empty array. + +Each item can be coerced from a string or a L<< C >> +instance, or a hashref of the form + + { address => $string, prefs => \%preferences_hash } + +The base Sietima class does not use any per-subscriber preferences, +but some roles do (L<< C|Sietima::Role::NoMail >>, for +example) + +=cut my $subscribers_array = ArrayRef[ Subscriber->plus_coercions( @@ -43,12 +138,33 @@ has subscribers => ( ); sub _build_subscribers { +[] } +=head2 C + +A L<< C >> instance, which will be used to +send messages. If not passed in, Sietima uses L<< +C >>'s L<< +C|Email::Sender::Simple/default_transport >>. + +=cut + has transport => ( isa => Transport, is => 'lazy', ); sub _build_transport { Email::Sender::Simple->default_transport } +=head1 METHODS + +=head2 C + + $sietima->handle_mail_from_stdin(); + +This is the main entry-point when Sietima is invoked from a MTA. It +will parse a L<< C >> object out of the standard input, +then pass it to L<< /C >> for processing. + +=cut + sub handle_mail_from_stdin($self,@) { my $mail_text = do { local $/; <> }; # we're hoping that, since we probably got called from an MTA/MDA, @@ -57,6 +173,16 @@ sub handle_mail_from_stdin($self,@) { return $self->handle_mail($incoming_mail); } +=head2 C + + $sietima->handle_mail($email_mime); + +Main driver method: converts the given email message into a list of +L<< C >> objects by calling L<< /C >>, +then sends each of them by calling L<< /C >>. + +=cut + sub handle_mail($self,$incoming_mail) { state $check = compile(Object,EmailMIME); $check->(@_); @@ -67,12 +193,42 @@ sub handle_mail($self,$incoming_mail) { return; } +=head2 C + + my $subscribers_aref = $sietima->subscribers_to_send_to($email_mime); + +Returns an array-ref of L<< C >> objects that +should receive copies of the given email message. + +In this base class, it just returns the value of the L<< +/C >> attribute. Roles such as L<< +C|Sietima::Role::AvoidDups >> modify this method to exclude +some subscribers. + +=cut + sub subscribers_to_send_to($self,$incoming_mail) { state $check = compile(Object,EmailMIME); $check->(@_); return $self->subscribers; } +=head2 C + + my @messages = $sietima->munge_mail($email_mime); + +Returns a list of L<< C >> objects representing the +messages to send to subscribers, based on the given email message. + +In this base class, this method returns a single instance to send to +all L<< /C >>, containing exactly the given +email message. + +Roles such as L<< C|Sietima::Role::SubjectTag >> modify +this method to alter the message. + +=cut + sub munge_mail($self,$incoming_mail) { state $check = compile(Object,EmailMIME); $check->(@_); @@ -83,6 +239,16 @@ sub munge_mail($self,$incoming_mail) { }); } +=head2 C + + $sietima->send_message($sietima_message); + +Sends the given L<< C >> object via the L<< +/C >>, but only if the message's +L specifies some recipients. + +=cut + sub send_message($self,$outgoing_message) { state $check = compile(Object,Message); $check->(@_); @@ -99,6 +265,42 @@ sub send_message($self,$outgoing_message) { sub _trait_namespace { 'Sietima::Role' } +=head2 C + + my $addresses_href = $sietima->list_addresses; + +Returns a hashref of L<< C >> instances or strings, +that declare various addresses related to this list. + +This base class declares only the L<< /C >>, and does not +use this method at all. + +The L<< C|Sietima::Role::Headers >> role uses this to +populate the various C headers. + +=cut + +sub list_addresses($self) { + return +{ + return_path => $self->return_path, + }; +} + +=head2 C + + my $app_spec_data = $sietima->command_line_spec; + +Returns a hashref describing the command line processing for L<< +C >>. L<< C >> uses this to build the +command line parser. + +This base class declares a single sub-command, C, that invokes +the L<< /C >> method. + +Roles can extend this to provide additional sub-commands and options. + +=cut + sub command_line_spec($self) { return { name => 'sietima', -- cgit v1.2.3