Mail-MtPolicyd
view release on metacpan or search on metacpan
lib/Mail/MtPolicyd/Client/Response.pm view on Meta::CPAN
package Mail::MtPolicyd::Client::Response;
use Moose;
our $VERSION = '2.05'; # VERSION
# ABSTRACT: a postfix policyd client response class
has 'action' => ( is => 'ro', isa => 'Str', required => 1 );
has 'attributes' => (
is => 'ro', isa => 'HashRef[Str]',
default => sub { {} },
);
sub as_string {
my $self = shift;
return join("\n",
map { $_.'='.$self->attributes->{$_} } keys %{$self->attributes},
)."\n\n";
}
sub new_from_fh {
my ( $class, $fh ) = ( shift, shift );
my $attr = {};
my $complete = 0;
while( my $line = $fh->getline ) {
$line =~ s/\r?\n$//;
if( $line eq '') { $complete = 1 ; last; }
my ( $name, $value ) = split('=', $line, 2);
if( ! defined $value ) {
die('error parsing response');
}
$attr->{$name} = $value;
}
if( ! $complete ) {
die('could not read response');
}
if( ! defined $attr->{'action'} ) {
die('no action found in response');
}
my $obj = $class->new(
'action' => $attr->{'action'},
'attributes' => $attr,
@_
);
return $obj;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Mail::MtPolicyd::Client::Response - a postfix policyd client response class
=head1 VERSION
version 2.05
=head1 DESCRIPTION
Class to handle a policyd response.
=head2 SYNOPSIS
( run in 2.719 seconds using v1.01-cache-2.11-cpan-0bb4e1dffa6 )