MtPolicyd/Client/Request.pm

filter: Statementstmt 21.6% 8 / 37 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 16.6% 1 / 6 Podpod 33.3% 1 / 3 totaltotal 18.5% 10 / 54 CC 5 SCAR 27.7
CC
5
Cov
18%
new_from_fh
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 15.9
« MtPolicyd/Client/Response.pm ↑ Summary MtPolicyd/Plugin/RBL.pm »
1 package Mail::MtPolicyd::Client::Request;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.12'; # VERSION
6 # ABSTRACT: a postfix policyd client request class
7  
8  
9 1 has 'type' => ( is => 'ro', isa => 'Str', default => 'smtpd_access_policy' );
10  
11 has 'instance' => ( is => 'ro', isa => 'Str', lazy => 1,
12 default => sub {
13 0 ▶ return rand;
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 },
15 1 );
16  
17 has 'attributes' => (
18 is => 'ro', isa => 'HashRef[Str]',
19 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 1 );
21  
22 sub as_string {
23 0 ▶ my $self = shift;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
24  
25 return join("\n",
26 'request='.$self->type,
27 'instance='.$self->instance,
28 0 map { $_.'='.$self->attributes->{$_} } keys %{$self->attributes},
29 )."\n\n";
30 }
31  
32 sub new_from_fh {
33 0 ▶ my ( $class, $fh ) = ( shift, shift );
Subroutine new_from_fh: not called CC=5 SCAR=34.0
Pod undocumented
34 0 my $attr = {};
35 0 my $complete = 0;
36 0 ▶ while( my $line = $fh->getline ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
37 0 $line =~ s/\r?\n$//;
38 0 ▶ if( $line eq '') { $complete = 1 ; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "") 0 0 0
39 0 my ( $name, $value ) = split('=', $line);
40 0 ▶ if( ! defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
41 0 die('error parsing response');
42 }
43 0 $attr->{$name} = $value;
44 }
45 0 ▶ if( ! $complete ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($complete) 0 0 0
46 0 die('could not read response');
47 }
48 0 my $obj = $class->new(
49 'attributes' => $attr,
50 @_
51 );
52 0 return $obj;
53 }
54  
55 sub new_proxy_request {
56 0 ▶ my ( $class, $r ) = ( shift, shift );
Subroutine new_proxy_request: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my %attr = %{$r->attributes};
58 0 delete($attr{'type'});
59 0 delete($attr{'instance'});
60  
61 0 my $obj = $class->new(
62 'type' => $r->type,
63 'instance' => $r->attr('instance'),
64 'attributes' => \%attr,
65 );
66 0 return $obj;
67 }
68  
69 1 1;
70  
71  
72 __END__
73 =pod
74  
75 =head1 NAME
76  
77 Mail::MtPolicyd::Client::Request - a postfix policyd client request class
78  
79 =head1 VERSION
80  
81 version 1.12
82  
83 =head1 DESCRIPTION
84  
85 Class for construction of policyd requests.
86  
87 =head2 SYNOPSIS
88  
89 use Mail::MtPolicyd::Client::Request;
90  
91 $request = Mail::MtPolicyd::Client::Request->new(
92 'client_address' => '127.0.0.1',
93 );
94  
95 =head2 METHODS
96  
97 =over
98  
99 =item as_string
100  
101 Returns the request in as a string in the policyd request format.
102  
103 =back
104  
105 =head2 ATTRIBUTES
106  
107 =over
108  
109 =item type (default: smtpd_access_policy)
110  
111 The type of the request.
112  
113 =item instance (default: rand() )
114  
115 The instance ID of the mail processed by the MTA.
116  
117 =item attributes (default: {} )
118  
119 A hashref with contains all key/value pairs of the request.
120  
121 =back
122  
123 =head1 AUTHOR
124  
125 Markus Benning <ich@markusbenning.de>
126  
127 =head1 COPYRIGHT AND LICENSE
128  
129 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
130  
131 This is free software, licensed under:
132  
133 The GNU General Public License, Version 2, June 1991
134  
135 =cut
136  
« MtPolicyd/Client/Response.pm ↑ Summary MtPolicyd/Plugin/RBL.pm »