Mail-MtPolicyd

 view release on metacpan or  search on metacpan

lib/Mail/MtPolicyd/Connection/Memcached.pm  view on Meta::CPAN

package Mail::MtPolicyd::Connection::Memcached;

use Moose;

our $VERSION = '2.05'; # VERSION
# ABSTRACT: a memcached connection plugin for mtpolicyd

extends 'Mail::MtPolicyd::Connection';


use Cache::Memcached;

has 'servers' => ( is => 'ro', isa => 'Str', default => '127.0.0.1:11211' );
has '_servers' => (
  is => 'ro', isa => 'ArrayRef[Str]', lazy => 1,
  default => sub {
    my $self = shift;
    return [ split(/\s*,\s*/, $self->servers) ];
  },
);

has 'debug' => ( is => 'ro', isa => 'Bool', default => 0 );
has 'namespace' => ( is => 'ro', isa => 'Str', default => '');

sub _create_handle {
  my $self = shift;
  return Cache::Memcached->new( {
    'servers' => $self->_servers,
    'debug' => $self->debug,
    'namespace' => $self->namespace,
  } );
}

has 'handle' => (
  is => 'rw', isa => 'Cache::Memcached', lazy => 1,
  default => sub {
    my $self = shift;
    $self->_create_handle
  },
);

sub reconnect {
  my $self = shift;
  $self->handle( $self->_create_handle );
  return;
}

sub shutdown {
  my $self = shift;
  $self->handle->disconnect_all;
  return;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Mail::MtPolicyd::Connection::Memcached - a memcached connection plugin for mtpolicyd

=head1 VERSION

version 2.05

=head1 SYNOPSIS

  <Connection memcached>
    module = "Memcached"
    servers = "127.0.0.1:11211"
    # namespace = "mt-"



( run in 0.585 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )