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/Request.pm ↑ Summary MtPolicyd/Client/Request.pm »
1 package Mail::MtPolicyd::Client::Response;
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 response class
7  
8  
9 1 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 1 );
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);
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 1 1;
52  
53  
54 __END__
55 =pod
56  
57 =head1 NAME
58  
59 Mail::MtPolicyd::Client::Response - a postfix policyd client response class
60  
61 =head1 VERSION
62  
63 version 1.12
64  
65 =head1 DESCRIPTION
66  
67 Class to handle a policyd response.
68  
69 =head2 SYNOPSIS
70  
71 use Mail::MtPolicyd::Client::Response;
72 my $response = Mail::MtPolicyd::Client::Response->new_from_fh( $conn );
73  
74 --
75  
76 my $response = Mail::MtPolicyd::Client::Response->new(
77 action => 'reject',
78 attributes => {
79 action => 'reject',
80 },
81 );
82  
83 print $response->as_string;
84  
85 =head2 METHODS
86  
87 =over
88  
89 =item new_from_fh( $filehandle )
90  
91 Constructor which reads a response from the supplied filehandle.
92  
93 =item as_string
94  
95 Returns a stringified version of the response.
96  
97 =back
98  
99 =head2 ATTRIBUTES
100  
101 =over
102  
103 =item action (required)
104  
105 The action specified in the reponse.
106  
107 =item attributes
108  
109 Holds a hash with all key/values of the response.
110  
111 =back
112  
113 =head1 AUTHOR
114  
115 Markus Benning <ich@markusbenning.de>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
120  
121 This is free software, licensed under:
122  
123 The GNU General Public License, Version 2, June 1991
124  
125 =cut
126  
« MtPolicyd/Request.pm ↑ Summary MtPolicyd/Client/Request.pm »