MtPolicyd/Client/Request.pm

filter: Statementstmt 26.6% 8 / 30 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 20.0% 1 / 5 Podpod 50.0% 1 / 2 totaltotal 22.2% 10 / 45 CC 5 SCAR 28.6
CC
5
Cov
21%
new_from_fh
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 17.4
« 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.11'; # 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 1 1;
56  
57  
58 __END__
59 =pod
60  
61 =head1 NAME
62  
63 Mail::MtPolicyd::Client::Request - a postfix policyd client request class
64  
65 =head1 VERSION
66  
67 version 1.11
68  
69 =head1 DESCRIPTION
70  
71 Class for construction of policyd requests.
72  
73 =head2 SYNOPSIS
74  
75 use Mail::MtPolicyd::Client::Request;
76  
77 $request = Mail::MtPolicyd::Client::Request->new(
78 'client_address' => '127.0.0.1',
79 );
80  
81 =head2 METHODS
82  
83 =over
84  
85 =item as_string
86  
87 Returns the request in as a string in the policyd request format.
88  
89 =back
90  
91 =head2 ATTRIBUTES
92  
93 =over
94  
95 =item type (default: smtpd_access_policy)
96  
97 The type of the request.
98  
99 =item instance (default: rand() )
100  
101 The instance ID of the mail processed by the MTA.
102  
103 =item attributes (default: {} )
104  
105 A hashref with contains all key/value pairs of the request.
106  
107 =back
108  
109 =head1 AUTHOR
110  
111 Markus Benning <ich@markusbenning.de>
112  
113 =head1 COPYRIGHT AND LICENSE
114  
115 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
116  
117 This is free software, licensed under:
118  
119 The GNU General Public License, Version 2, June 1991
120  
121 =cut
122  
« MtPolicyd/Client/Response.pm ↑ Summary MtPolicyd/Plugin/RBL.pm »