File Coverage

blib/lib/Mail/Qmail/Filter/Dump.pm
Criterion Covered Total %
statement 8 16 50.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 12 28 42.8


line stmt bran cond sub pod time code
1 1     1   782 use 5.014;
  1         3  
2 1     1   5 use warnings;
  1         2  
  1         41  
3              
4              
5             our $VERSION = '1.01';
6              
7             use Mo qw(coerce required);
8 1     1   4 extends 'Mail::Qmail::Filter';
  1         2  
  1         4  
9              
10             has 'to' => required => 1;
11              
12             my $self = shift;
13             my $message = $self->message;
14 0     0 1   require Path::Tiny and Path::Tiny->import('path')
15 0           unless defined &path;
16 0 0 0       my $dest = path( $self->to );
17             state $i = 0;
18 0           $dest = $dest->child( join '_', $^T, $$, ++$i ) if $dest->is_dir;
19 0           $dest->spew( $message->body );
20 0 0         $self->debug( 'dumped message to' => $dest );
21 0           }
22 0            
23             1;
24              
25              
26             =head1 NAME
27              
28             Mail::Qmail::Filter::Dump -
29             dump message to file
30              
31             =head1 SYNOPSIS
32              
33             use Mail::Qmail::Filter;
34              
35             Mail::Qmail::Filter->new->add_filter(
36             '::Dump' => {
37             'to' => '/path/to/write/to',
38             }
39             )->run;
40              
41             =head1 DESCRIPTION
42              
43             This L<Mail::Qmail::Filter> plugin writes the message to a file
44             (for debugging purposes).
45              
46             =head1 REQUIRED PARAMETERS
47              
48             =head2 to
49              
50             Where to write the message to.
51              
52             May be the name of a file or an existing directory.
53             In the latter case, will create a file named
54             C<E<lt>epoch_time_when_script_startedE<gt>_E<lt>pidE<gt>_E<lt>serial_numberE<gt>>
55             in that directory.
56              
57             =head1 SEE ALSO
58              
59             L<Mail::Qmail::Filter/COMMON PARAMETERS FOR ALL FILTERS>
60              
61             =head1 LICENSE AND COPYRIGHT
62              
63             Copyright 2019 Martin Sluka.
64              
65             This module is free software; you can redistribute it and/or modify it
66             under the terms of the the Artistic License (2.0). You may obtain a
67             copy of the full license at:
68              
69             L<http://www.perlfoundation.org/artistic_license_2_0>
70              
71             Any use, modification, and distribution of the Standard or Modified
72             Versions is governed by this Artistic License. By using, modifying or
73             distributing the Package, you accept this license. Do not use, modify,
74             or distribute the Package, if you do not accept this license.
75              
76             If your Modified Version has been derived from a Modified Version made
77             by someone other than you, you are nevertheless required to ensure that
78             your Modified Version complies with the requirements of this license.
79              
80             This license does not grant you the right to use any trademark, service
81             mark, tradename, or logo of the Copyright Holder.
82              
83             This license includes the non-exclusive, worldwide, free-of-charge
84             patent license to make, have made, use, offer to sell, sell, import and
85             otherwise transfer the Package with respect to any patent claims
86             licensable by the Copyright Holder that are necessarily infringed by the
87             Package. If you institute patent litigation (including a cross-claim or
88             counterclaim) against any party alleging that the Package constitutes
89             direct or contributory patent infringement, then this Artistic License
90             to you shall terminate on the date that such litigation is filed.
91              
92             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
93             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
94             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
95             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
96             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
97             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
98             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
99             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100              
101             =cut