this repo has no description

Compare changes

Choose any two refs to compare.

+4
.gitignore
···
+
MYMETA.yml
+
Makefile
+
blib/
+
pm_to_blib
+8
.travis.yml
···
+
language: perl
+
perl:
+
- "5.16"
+
- "5.14"
+
- "5.12"
+
- "5.10"
+
- "5.8"
+
services: mongodb
+1 -1
Changes
···
Revision history for CHI-Driver-MongoDB
-
0.01 Date/time
+
0.01 May 18, 2011
Initial version.
+6 -5
MANIFEST
···
Changes
INSTALL
LICENSE
-
lib/CHI/Driver/MongoDB.pm
+
MANIFEST
+
META.json
+
META.yml
Makefile.PL
-
MANIFEST This list of files
+
lib/CHI/Driver/MongoDB.pm
+
lib/CHI/Driver/MongoDB/t/CHIDriverTests/MongoDB.pm
README
t/00-load.t
-
t/manifest.t
-
t/pod-coverage.t
-
t/pod.t
+
t/CHIDriverTests-MongoDB.t
+53
META.json
···
+
{
+
"abstract" : "Use MongoDB for cache storage",
+
"author" : [
+
"Nick Mohoric <nick.mohoric@gmail.com>"
+
],
+
"dynamic_config" : 0,
+
"license" : [
+
"perl_5"
+
],
+
"meta-spec" : {
+
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+
"version" : "2"
+
},
+
"name" : "CHI-Driver-MongoDB",
+
"no_index" : {
+
"directory" : [
+
"lib/CHI/Driver/MongoDB/t",
+
],
+
},
+
"prereqs" : {
+
"configure" : {
+
"requires" : {
+
"ExtUtils::MakeMaker" : "6.31"
+
}
+
},
+
"runtime" : {
+
"requires" : {
+
"CHI" : "0.241",
+
"MongoDB" : "0.42"
+
}
+
},
+
"test" : {
+
"requires" : {
+
"Test::Class" : 0,
+
"Test::More" : 0
+
}
+
}
+
},
+
"release_status" : "stable",
+
"resources" : {
+
"bugtracker" : {
+
"mailto" : "bug-chi-driver-mongodb@rt.cpan.org",
+
"web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=CHI-Driver-MongoDB"
+
},
+
"repository" : {
+
"type" : "git",
+
"url" : "git://github.com/AddingMachine/Chi-Driver-MongoDB.git",
+
"web" : "https://github.com/AddingMachine/Chi-Driver-MongoDB"
+
}
+
},
+
"version" : "0.01"
+
}
+
+25
META.yml
···
+
---
+
abstract: 'Use MongoDB for cache storage'
+
author:
+
- 'Nick Mohoric <nick.mohoricc@gmail.com>'
+
build_requires:
+
Test::Class: 0
+
Test::More: 0
+
configure_requires:
+
ExtUtils::MakeMaker: 6.31
+
dynamic_config: 0
+
license: perl
+
meta-spec:
+
url: http://module-build.sourceforge.net/META-spec-v1.4.html
+
version: 1.4
+
name: CHI-Driver-MongoDB
+
no_index:
+
directory:
+
- lib/CHI/Driver/MongoDB/t
+
requires:
+
CHI: 0.241
+
MongoDB: 0.42
+
resources:
+
bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=CHI-Driver-MongoDB
+
repository: git://github.com/AddingMachine/Chi-Driver-MongoDB.git
+
version: 0.01
+8 -3
Makefile.PL
···
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
+
BUILD_REQUIRES => {
+
'Test::Class' => '0',
+
'Test::More' => '0'
+
},
+
CONFIGURE_REQUIRES => {
+
'ExtUtils::MakeMaker' => '6.31'
+
},
+
LICENSE => 'perl',
PREREQ_PM => {
-
'Test::More' => 0,
'CHI' => '0.241',
'MongoDB' => '0.42',
},
-
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
-
clean => { FILES => 'CHI-Driver-MongoDB-*' },
test => { TESTS => 't/*.t' },
);
+11 -2
lib/CHI/Driver/MongoDB/t/CHIDriverTests/MongoDB.pm
···
};
}
+
sub new_cache_options {
+
my $self = shift;
+
+
return (
+
$self->SUPER::new_cache_options(),
+
db => $self->db,
+
);
+
}
+
sub test_with_database : Tests(1) {
return "MongoDB::Database not installed"
unless can_load( modules => { "MongoDB::Database" => undef } );
-
my $self = shift;
+
my $self = shift;
my $cache = CHI->new(
driver => "MongoDB",
db => $self->db
···
return "MongoDB::Connection not installed"
unless can_load( modules => { "MongoDB::Connection" => undef } );
-
my $self = shift;
+
my $self = shift;
my $cache = CHI->new(
driver => "MongoDB",
conn => MongoDB::Connection->new,
+23 -19
lib/CHI/Driver/MongoDB.pm
···
extends 'CHI::Driver';
-
has 'conn' => ( is => 'ro', isa => 'MongoDB::Connection' );
-
has 'db' => ( is => 'ro', isa => 'MongoDB::Database' );
-
has 'db_name' => ( is => 'ro', isa => 'Str', default => 'chi' );
+
has 'conn' => ( is => 'ro', isa => 'MongoDB::Connection' );
+
has 'db' => ( is => 'ro', isa => 'MongoDB::Database' );
+
has 'collection' => ( is => 'ro', isa => 'MongoDB::Collection' );
+
has 'db_name' => ( is => 'ro', isa => 'Str', default => 'chi' );
+
has 'safe' => ( is => 'rw', isa => 'Bool', default => 0 );
__PACKAGE__->meta->make_immutable();
sub BUILD {
my ( $self, $args ) = @_;
-
return if $self->{db};
-
if ( $self->{conn} && $self->{db_name} ) {
$self->{db} = $self->{conn}->get_database( $self->{db_name} );
}
-
else {
+
elsif ( !$self->{db} ) {
croak 'No Database Set';
}
-
return;
-
}
+
$self->{collection} = $self->db->get_collection( $self->namespace() );
-
sub _collection {
-
my ($self) = @_;
-
return $self->db->get_collection( $self->namespace() );
+
return;
}
sub fetch {
my ( $self, $key ) = @_;
-
my $results =
-
$self->_collection->find_one( { _id => $key }, { data => 1 } );
+
+
my $results = $self->collection->find_one( { _id => "$key" }, { data => 1 } );
return ($results) ? $results->{data} : undef;
}
sub store {
my ( $self, $key, $data ) = @_;
-
$self->_collection->save( { _id => $key, data => $data }, { safe => 1 } );
+
+
$self->collection->save( { _id => "$key", data => $data },
+
{ safe => $self->{safe} } );
return;
}
sub remove {
my ( $self, $key ) = @_;
-
$self->_collection->remove( { _id => $key }, { safe => 1 } );
+
+
$self->collection->remove( { _id => "$key" }, { safe => $self->{safe} } );
return;
}
sub clear {
-
shift->_collection->drop;
+
shift->collection->drop;
return;
}
sub get_keys {
-
return map { $_->{_id} } shift->_collection->find( {}, { _id => 1 } )->all;
+
map { $_->{_id} } shift->collection->find( {}, { _id => 1 } )->all;
}
sub get_namespaces {
-
return shift->db->collection_names( { safe => 1 } );
+
return shift->db->collection_names();
}
1;
···
=item db_name
-
Option database name to use in conjunction with the conn
+
Optional database name to use in conjunction with the conn
+
+
=item safe
+
+
Optional flag to confirm insertion/removal. This will slow down writes significantly.
=back
+1 -1
t/CHIDriverTests-MongoDB.t
···
#!perl -w
use strict;
use warnings;
-
use CHI::Driver::MongoDB::t:CHIDriverTests::MongoDB;
+
use CHI::Driver::MongoDB::t::CHIDriverTests::MongoDB;
CHI::Driver::MongoDB::t::CHIDriverTests::MongoDB->runtests;
-12
t/pod.t
···
-
#!perl -T
-
-
use strict;
-
use warnings;
-
use Test::More;
-
-
# Ensure a recent version of Test::Pod
-
my $min_tp = 1.22;
-
eval "use Test::Pod $min_tp";
-
plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
-
-
all_pod_files_ok();