The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mail::Lite::Processor -- processing (identifying, parsing, extracting data from) mail-like message (also Jabber and so on)

SYNOPSIS

    use Data::Dumper;
    use Mail::Lite::Processor;

    my $message = new Mail::Lite::Message( do { local $/; <DATA> } );

    my $processor = new Mail::Lite::Processor(
        rules => [
            {
                id => 'fail',
                match => [ 
                    {
                        subject => 'FAILED'
                    }
                ]
            },
            {
                id => 'success',
                match => [ 
                    {
                        subject => 'SUCCESS'
                    }
                ],
                processors => [
                    {
                        processor => 'regexp',
                        regexps   => {
                            'status=~body,once' => 'Status: (.*)',
                        },
                    }
                ]
            },
        ],
    );

    $processor->process(
        message => $message,
        handler => sub { warn Dumper \@_ },
    );

    __DATA__
    From test@cpan.org
    Subject: SUCCESS


    Status: all your base are belong to us

    __END__

DESCRIPTION

Common

A lot of data comes in mails, so you just have to read them and parse.

In order to automate the process of identifying mails and fetching some data was created this module. One can use it to parse mails from various bots, standarterized (and not) responces and so on. Author uses it primary for parsing mails from RU TLD registry.

Format of rules

Processing of message is done by list of rules. Each rule have implicit internal processor -- 'match', which is checks if message fits to this rule. If so, then a list of 'processors' is executed. After that user-supported handler is called with results from all these processors. Note that by default all the matched rules are treated and copy of message is processed with each of them. You can change this behaviour by specifiyng 'last' in rule specification.

As sometimes there is info about many objects in single message, there is way to split and then identify and parse parts independently. See Mail::Lite::Processor::Split, Mail::Lite::Processor::Chain.

Processors

For further info about:

SUBROUTINES/METHODS

An object of this class represents instance of processor which maintains it own set of rules for processing.

new( rules => [ ... ], handler => sub { ... }, debug => [ 0 | 1 ] )

Create new processor instance with rules arrayref, which will call handler sub for each processed message. Optionally you can set debug level.

$processor->process( message => [ text or Mail::Lite::Message instance ], handler => sub { ... } )

Process message within this processor, call handler.

Mail::Lite::Processor->process( rules => [ ... ], message => [ text or Mail::Lite::Message instance ], handler => sub { ... } )

Same as above, but create instance for given rules.

DIAGNOSTICS

A list of every error and warning message that the module can generate (even the ones that will "never happen"), with a full explanation of each problem, one or more likely causes, and any suggested remedies.

CONFIGURATION AND ENVIRONMENT

A full explanation of any configuration system(s) used by the module, including the names and locations of any configuration files, and the meaning of any environment variables or properties that can be set. These descriptions must also include details of any configuration language used.

DEPENDENCIES

A list of all the other modules that this module relies upon, including any restrictions on versions, and an indication whether these required modules are part of the standard Perl distribution, part of the module's distribution, or must be installed separately.

INCOMPATIBILITIES

A list of any modules that this module cannot be used in conjunction with. This may be due to name conflicts in the interface, or competition for system or program resources, or due to internal limitations of Perl (for example, many modules that use source code filters are mutually incompatible).

BUGS AND LIMITATIONS

A list of known problems with the module, together with some indication whether they are likely to be fixed in an upcoming release.

Also a list of restrictions on the features the module does provide: data types that cannot be handled, performance issues and the circumstances in which they may arise, practical limitations on the size of data sets, special cases that are not (yet) handled, etc.

The initial template usually just has:

There are no known bugs in this module. Please report problems to <Maintainer name(s)> (<contact address>) Patches are welcome.

AUTHOR

Pavel Boldin (davinchi@cpan.org)

LICENCE AND COPYRIGHT

Copyright (c) 2009 (davinchi@cpan.org). All rights reserved.

Followed by whatever licence you wish to release it under. For Perl code that is often just:

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perldoc perlartistic.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.