Auth-Kokolores

 view release on metacpan or  search on metacpan

lib/Auth/Kokolores/Plugin/MemcachedConnection.pm  view on Meta::CPAN

package Auth::Kokolores::Plugin::MemcachedConnection;

use Moose;
use Cache::Memcached;

# ABSTRACT: kokolores plugin to configure a memcached connection
our $VERSION = '1.01'; # VERSION

extends 'Auth::Kokolores::Plugin';

use Auth::Kokolores::ConnectionPool;


has 'servers' => ( is => 'ro', isa => 'Str', default => '127.0.0.1:11211');
has 'namespace' => ( is => 'ro', isa => 'Str', default => 'auth-');
has 'handle' => ( is => 'rw', isa => 'Str', default => 'memcached' );

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

has 'memcached' => (
  is => 'ro', isa => 'Cache::Memcached',
  lazy => 1,
  default => sub {
    my $self = shift;
    $self->log(3, 'creating memcached connection to '.join(', ', @{$self->_servers}).'...');
    return Cache::Memcached->new( {
      'servers' => $self->_servers,
      'debug' => 0,
      'namespace' => $self->namespace,
    } );
  },
);

sub child_init {
  my ( $self, $r ) = @_;
  
  $self->log(3, 'registring memcached connection \''.$self->handle.'\'...');
  Auth::Kokolores::ConnectionPool->add_handle(
    $self->handle => $self->memcached,
  );

  return;
}

sub shutdown {
  my ( $self, $r ) = @_;
  
  $self->log(3, 'unregistring memcached connection \''.$self->handle.'\'...');
  Auth::Kokolores::ConnectionPool->clear_handle( $self->handle );

  return;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Auth::Kokolores::Plugin::MemcachedConnection - kokolores plugin to configure a memcached connection

=head1 VERSION

version 1.01

=head1 DESCRIPTION

This plugin creates a connection to an memcached server for use
by further plugins.



( run in 0.326 second using v1.01-cache-2.11-cpan-5511b514fd6 )