logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Sympa::Spindle - Base class of subclasses to define Sympa workflows

Description

       Sympa::Spindle is the base class of subclasses to define particular workflows of Sympa.

       A spindle class is a set of features to process objects.  If spin() method is called, it retrieves each
       object from source spool, processes it, at last passes altered object to appropriate destination (another
       spool or mailer), and removes it as necessity.  Processing repeats until source spool is empty.

   Publicmethods
       new ( [ key => value, ... ] )
           Constructor.  Creates new instance of Sympa::Spindle.

       spin ( )
           Instancemethod.   Fetches an object and handle locking it from source spool, processes them calling
           _twist() and repeats.  If source spool no longer gives  content,  returns  the  number  of  processed
           objects.

       add_stash ( =parameters... )
           Instancemethod.  Adds arrayref of parameters to a storage for general-purpose.

   Properties
       Instance of Sympa::Spindle may have following properties.

       {distaff}
           Instance of source spool class _distaff() method returns.

       {finish}
           Read/write.  At first this property is false.  Once it is set, spin() finishes processing safely.

       Spools
           Instances of spool classes _spools() method returns.

       {start_time}
           Unix time in floating point number when processing of the latest message by spin() began.  Introduced
           by Sympa 6.2.13.

       {stash}
           A reference to array of added data by add_stash().

   Methodssubclassshouldimplement
       _distaff ( )
           Classmethod,  mandatory  if  you want to implement spin().  Returns the name of source spool class.
           source spool class must implement new() and next().

       _init ( $state )
           Instancemethod.  Additional processing when the spindle class is instantiated ($state is 0),  before
           spin()  processes  next  object in source spool ($state is 1) or after it processed object ($state is
           2).

           If it returns false value, new() will return "undef" (when $state is  0)  or  spin()  will  terminate
           processing (when $state is 1).  By default it always returns 1.

       _on_garbage ( $handle )
           Instancemethod,  overridable.  Executes process when object could not be deserialized (new() method
           of object failed).  By default, quarantines object calling quarantine() method of source spool.

       _on_failure ( $message, $handle )
           Instancemethod, overridable.  Executes process when processing of $message failed (_twist() returned
           "undef").  By default, quarantines object calling quarantine() method of source spool.

       _on_skip ( $message, $handle )
           Instancemethod, overridable.  Executes process when $message was skipped (_twist() returned 0).   By
           default, simply unlocks object calling close() method of $handle.

       _on_success ( $message, $handle )
           Instancemethod,  overridable.   Executes  process  when  processing of $message succeeded (_twist()
           returned true value).  By default, removes object calling remove() method of source spool.

       _spools ( )
           Classmethod.  If implemented, returns hashref with names of spool classes related to the spindle  as
           values.

       _twist ( $message )
           Instancemethod,  mandatory.   Processes  an  object:  Typically, modifies object or creates another
           object and stores it into appropriate spool.

           Parameter:

           $message
               An object.

           Returns:

           Status of processing: True value on success; 0 if processing skipped; "undef" on failure.

           As of Sympa 6.2.13, _twist() may also return the  reference  to  array  including  name(s)  of  other
           classes:  In  this  case  spin() and twist() will call _twist() method of given classes in order (not
           coercing spindle object into them) and uses returned false value at first or true value at last.

History

       Sympa::Spindle appeared on Sympa 6.2.10.

6.2.76                                             2025-02-12                             Sympa::Spindle(3Sympa)

Name

       Sympa::Spindle - Base class of subclasses to define Sympa workflows

See Also

       Sympa::Internals::Workflow, Sympa::Spool.

Synopsis

         package Sympa::Spindle::FOO;
         use base qw(Sympa::Spindle);

         use constant _distaff => 'Sympa::Spool::BAR';

         sub _twist {
             my $self = shift;
             my $object = shift;

             # Process object...

             return 1;                        # If succeeded.
             return 0;                        # If skipped.
             return undef;                    # If failed.
             return ['Sympa::Spindle::BAZ'];  # Splicing to the other class(es).
         }

         1;

See Also