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/Plugin/Stress.pm ↑ Summary MtPolicyd/Plugin/ScoreAction.pm »
1 package Mail::MtPolicyd::Client::Request;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = '2.01'; # VERSION
6 # ABSTRACT: a postfix policyd client request class
7  
8  
9 2 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 2 );
16  
17 has 'attributes' => (
18 is => 'ro', isa => 'HashRef[Str]',
19 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 2 );
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, 2);
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 2 1;
70  
71 __END__
72  
73 =pod
74  
75 =encoding UTF-8
76  
77 =head1 NAME
78  
79 Mail::MtPolicyd::Client::Request - a postfix policyd client request class
80  
81 =head1 VERSION
82  
83 version 2.01
84  
85 =head1 DESCRIPTION
86  
87 Class for construction of policyd requests.
88  
89 =head2 SYNOPSIS
90  
91 use Mail::MtPolicyd::Client::Request;
92  
93 $request = Mail::MtPolicyd::Client::Request->new(
94 'client_address' => '127.0.0.1',
95 );
96  
97 =head2 METHODS
98  
99 =over
100  
101 =item as_string
102  
103 Returns the request in as a string in the policyd request format.
104  
105 =back
106  
107 =head2 ATTRIBUTES
108  
109 =over
110  
111 =item type (default: smtpd_access_policy)
112  
113 The type of the request.
114  
115 =item instance (default: rand() )
116  
117 The instance ID of the mail processed by the MTA.
118  
119 =item attributes (default: {} )
120  
121 A hashref with contains all key/value pairs of the request.
122  
123 =back
124  
125 =head1 AUTHOR
126  
127 Markus Benning <ich@markusbenning.de>
128  
129 =head1 COPYRIGHT AND LICENSE
130  
131 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
132  
133 This is free software, licensed under:
134  
135 The GNU General Public License, Version 2, June 1991
136  
137 =cut
« MtPolicyd/Plugin/Stress.pm ↑ Summary MtPolicyd/Plugin/ScoreAction.pm »