Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Implementation Store engine
Browse files Browse the repository at this point in the history
It will allow to store SCK data on other DB engine than Redis.
Next step will be MongoDB
  • Loading branch information
geistteufel committed Apr 13, 2012
1 parent c1eba26 commit 0aa03d9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/Celogeek/SCK/Store.pm
@@ -0,0 +1,31 @@
package Celogeek::SCK::Store;

# ABSTRACT: handle storage of SCK website

use strict;
use warnings;
# VERSION
use Moo;

has 'engine' => (
is => 'ro',
isa => sub {
die "not a valid engine" unless $_[0] =~ /^redis$/;
},
required => 1,
);

has 'connection' => (
is => 'ro',
required => 1,
);

sub BUILD {
my $self = shift;
my $store = __PACKAGE__.'::'.ucfirst($self->engine);
with $store;
with __PACKAGE__.'::Base';
$self->validate_connection();
}

1;
26 changes: 26 additions & 0 deletions lib/Celogeek/SCK/Store/Base.pm
@@ -0,0 +1,26 @@
package Celogeek::SCK::Store::Base;

# ABSTRACT: Empty store, to force implementation of method

use strict;
use warnings;
# VERSION

use Moo::Role;

sub _die {
my $self = shift;
my $store_class = substr(__PACKAGE__,0,-length('Base')).ucfirst($self->engine);
my $func = substr((caller(1))[3], length(__PACKAGE__) + 2);
die "${store_class}::${func} need to be implemented";
}

#method need to be implemented
for my $meth (qw/validate_connection set_config get_config/) {
eval <<EOF
sub $meth { shift->_die }
EOF
;
}

1;

0 comments on commit 0aa03d9

Please sign in to comment.