File Coverage

blib/lib/Mail/MtPolicyd/Plugin.pm
Criterion Covered Total %
statement 11 15 73.3
branch 1 2 50.0
condition n/a
subroutine 4 6 66.6
pod 2 4 50.0
total 18 27 66.6


line stmt bran cond sub pod time code
1             package Mail::MtPolicyd::Plugin;
2              
3 18     18   10346 use Moose;
  18         28  
  18         111  
4 18     18   74058 use namespace::autoclean;
  18         5618  
  18         114  
5              
6             our $VERSION = '2.01'; # VERSION
7             # ABSTRACT: a base class for plugins
8              
9              
10             has 'name' => ( is => 'rw', isa => 'Str', required => 1 );
11             has 'log_level' => ( is => 'ro', isa => 'Int', default => 4 );
12             has 'vhost_name' => ( is => 'ro', isa => 'Maybe[Str]' );
13              
14             has 'on_error' => ( is => 'ro', isa => 'Maybe[Str]' );
15              
16              
17             sub run {
18 0     0 1 0 my ( $self, $r ) = @_;
19 0         0 die('plugin did not implement run method!');
20             }
21              
22             sub log {
23 137     137 1 667 my ($self, $r, $msg) = @_;
24 137 50       3476 if( defined $self->vhost_name ) {
25 0         0 $msg = $self->vhost_name.': '.$msg;
26             }
27 137         3279 $r->log($self->log_level, $msg);
28              
29 137         25850 return;
30             }
31              
32             sub init {
33 4     4 0 1817 return;
34             }
35              
36             sub cron {
37 0     0 0   return;
38             }
39              
40             __PACKAGE__->meta->make_immutable;
41              
42             1;
43              
44             __END__
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             Mail::MtPolicyd::Plugin - a base class for plugins
53              
54             =head1 VERSION
55              
56             version 2.01
57              
58             =head1 ATTRIBUTES
59              
60             =head2 name
61              
62             Contains a string with the name of this plugin as specified in the configuration.
63              
64             =head2 log_level (default: 4)
65              
66             The log_level used when the plugin calls $self->log( $r, $msg ).
67              
68             =head1 METHODS
69              
70             =head2 run( $r )
71              
72             This method has be implemented by the plugin which inherits from this base class.
73              
74             =head2 log( $r, $msg )
75              
76             This method could be used by the plugin to log something.
77              
78             Since this is mostly for debugging the default is to log plugin specific
79             messages with log_level=4. (see log_level attribute)
80              
81             =head1 AUTHOR
82              
83             Markus Benning <ich@markusbenning.de>
84              
85             =head1 COPYRIGHT AND LICENSE
86              
87             This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
88              
89             This is free software, licensed under:
90              
91             The GNU General Public License, Version 2, June 1991
92              
93             =cut