CHI-Driver-MongoDB
view release on metacpan or search on metacpan
lib/CHI/Driver/MongoDB.pm view on Meta::CPAN
package CHI::Driver::MongoDB;
# vim:syntax=perl:tabstop=4:number:noexpandtab:
$CHI::Driver::MongoDB::VERSION = '0.0101';
# ABSTRACT: MongoDB driver for CHI
use Moo;
use MongoDB;
use BSON;
use BSON::Types qw( bson_bytes bson_time );
use URI::Escape::XS;
use Try::Tiny;
use strict;
use warnings;
extends 'CHI::Driver';
has 'mongodb' => (
is => 'ro',
lazy => 1,
init_arg => undef,
builder => '_build_mongodb',
);
has 'mongodb_options' => (
is => 'rw',
default => sub { {} },
);
has 'connection_uri' => (
is => 'ro',
lazy => 1,
default => sub { 'mongodb://127.0.0.1:27017' },
);
has 'db_name' => (
is => 'ro',
lazy => 1,
default => sub {'_CHI_'},
);
has '_coll' => (
is => 'rw',
lazy => 1,
predicate => 1,
init_arg => undef,
builder => '_build_coll',
clearer => 1,
);
sub BUILD {
my ( $self, $params ) = @_;
foreach my $param (qw/ mongodb_options connection_uri db_name /) {
if ( exists $params->{$param} ) {
delete $params->{$param};
}
}
my %options = (
%{ $self->mongodb_options() },
%{ $self->non_common_constructor_params($params) },
);
$self->mongodb_options( \%options );
}
sub _build_mongodb {
my $self = shift;
my %opts = %{ $self->mongodb_options() };
( run in 2.888 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )