Mail-MtPolicyd
view release on metacpan or search on metacpan
lib/Mail/MtPolicyd/Client/Request.pm view on Meta::CPAN
package Mail::MtPolicyd::Client::Request;
use Moose;
our $VERSION = '2.05'; # VERSION
# ABSTRACT: a postfix policyd client request class
has 'type' => ( is => 'ro', isa => 'Str', default => 'smtpd_access_policy' );
has 'instance' => ( is => 'ro', isa => 'Str', lazy => 1,
default => sub {
return rand;
},
);
has 'attributes' => (
is => 'ro', isa => 'HashRef[Str]',
default => sub { {} },
);
sub as_string {
my $self = shift;
return join("\n",
'request='.$self->type,
'instance='.$self->instance,
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');
}
my $obj = $class->new(
'attributes' => $attr,
@_
);
return $obj;
}
sub new_proxy_request {
my ( $class, $r ) = ( shift, shift );
my %attr = %{$r->attributes};
delete($attr{'type'});
delete($attr{'instance'});
my $obj = $class->new(
'type' => $r->type,
'instance' => $r->attr('instance'),
'attributes' => \%attr,
);
return $obj;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
( run in 3.142 seconds using v1.01-cache-2.11-cpan-f56aa216473 )