MtPolicyd/Client/Response.pm

filter: Statementstmt 23.3% 7 / 30 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 1 / 4 Podpod 100% 2 / 2 totaltotal 21.7% 10 / 46 CC 6 SCAR 33.5
CC
6
Cov
18%
new_from_fh
42.0
__ANON__
2.0
as_string
2.0
CRAP 28.6
« MtPolicyd/Plugin/Greylist.pm ↑ Summary MtPolicyd/Request.pm »
1 package Mail::MtPolicyd::Client::Response;
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 response class
7  
8  
9 2 has 'action' => ( is => 'ro', isa => 'Str', required => 1 );
10  
11 has 'attributes' => (
12 is => 'ro', isa => 'HashRef[Str]',
13 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 2 );
15  
16 sub as_string {
17 0 ▶ my $self = shift;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
18  
19 return join("\n",
20 0 map { $_.'='.$self->attributes->{$_} } keys %{$self->attributes},
21 )."\n\n";
22 }
23  
24 sub new_from_fh {
25 0 ▶ my ( $class, $fh ) = ( shift, shift );
Subroutine new_from_fh: not called CC=6 SCAR=37.4
Pod documented
26 0 my $attr = {};
27 0 my $complete = 0;
28 0 ▶ while( my $line = $fh->getline ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $fh->getline) 0 0 0
29 0 $line =~ s/\r?\n$//;
30 0 ▶ if( $line eq '') { $complete = 1 ; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "") 0 0 0
31 0 my ( $name, $value ) = split('=', $line, 2);
32 0 ▶ if( ! defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
33 0 die('error parsing response');
34 }
35 0 $attr->{$name} = $value;
36 }
37 0 ▶ if( ! $complete ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($complete) 0 0 0
38 0 die('could not read response');
39 }
40 0 ▶ if( ! defined $attr->{'action'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $attr->{"action"}) 0 0 0
41 0 die('no action found in response');
42 }
43 my $obj = $class->new(
44 0 'action' => $attr->{'action'},
45 'attributes' => $attr,
46 @_
47 );
48 0 return $obj;
49 }
50  
51 2 1;
52  
53 __END__
54  
55 =pod
56  
57 =encoding UTF-8
58  
59 =head1 NAME
60  
61 Mail::MtPolicyd::Client::Response - a postfix policyd client response class
62  
63 =head1 VERSION
64  
65 version 2.01
66  
67 =head1 DESCRIPTION
68  
69 Class to handle a policyd response.
70  
71 =head2 SYNOPSIS
72  
73 use Mail::MtPolicyd::Client::Response;
74 my $response = Mail::MtPolicyd::Client::Response->new_from_fh( $conn );
75  
76 --
77  
78 my $response = Mail::MtPolicyd::Client::Response->new(
79 action => 'reject',
80 attributes => {
81 action => 'reject',
82 },
83 );
84  
85 print $response->as_string;
86  
87 =head2 METHODS
88  
89 =over
90  
91 =item new_from_fh( $filehandle )
92  
93 Constructor which reads a response from the supplied filehandle.
94  
95 =item as_string
96  
97 Returns a stringified version of the response.
98  
99 =back
100  
101 =head2 ATTRIBUTES
102  
103 =over
104  
105 =item action (required)
106  
107 The action specified in the reponse.
108  
109 =item attributes
110  
111 Holds a hash with all key/values of the response.
112  
113 =back
114  
115 =head1 AUTHOR
116  
117 Markus Benning <ich@markusbenning.de>
118  
119 =head1 COPYRIGHT AND LICENSE
120  
121 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
122  
123 This is free software, licensed under:
124  
125 The GNU General Public License, Version 2, June 1991
126  
127 =cut
« MtPolicyd/Plugin/Greylist.pm ↑ Summary MtPolicyd/Request.pm »