[libmagpie-perl] 06/30: Moved DBI-related Resource attributes out to their own reusable plugin.

Jonas Smedegaard dr at jones.dk
Wed Dec 6 00:56:38 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/1.163200-1
in repository libmagpie-perl.

commit ad7c8c02e9cdea5fd369705a208b241f3f087ac3
Author: Kip Hampton <khampton at totalcinema.com>
Date:   Mon Nov 14 17:16:36 2016 -0800

    Moved DBI-related Resource attributes out to their own reusable plugin.
---
 lib/Magpie/Plugin/DBI.pm     | 23 ------------------
 lib/Magpie/Resource/Kioku.pm | 56 ++------------------------------------------
 2 files changed, 2 insertions(+), 77 deletions(-)

diff --git a/lib/Magpie/Plugin/DBI.pm b/lib/Magpie/Plugin/DBI.pm
index a962e33..c83746b 100644
--- a/lib/Magpie/Plugin/DBI.pm
+++ b/lib/Magpie/Plugin/DBI.pm
@@ -55,28 +55,5 @@ sub _connect_args {
     \@args;
 }
 
-sub _build_data_source {
-    my $self = shift;
-    my $k    = undef;
-
-    try {
-        $k = $self->resolve_asset( service => 'kioku_dir' );
-    }
-    catch {
-        try {
-            $k = KiokuDB->connect( @{ $self->_connect_args } );
-        }
-        catch {
-            my $error = "Could not connect to Kioku data source: $_\n";
-            warn $error;
-            $self->set_error( { status_code => 500, reason => $error } );
-        };
-    };
-
-    return undef if $self->has_error;
-    $self->_kioku_scope( $k->new_scope );
-    return $k;
-}
-
 
 1;
diff --git a/lib/Magpie/Resource/Kioku.pm b/lib/Magpie/Resource/Kioku.pm
index 5e4ea10..0e72d2a 100644
--- a/lib/Magpie/Resource/Kioku.pm
+++ b/lib/Magpie/Resource/Kioku.pm
@@ -4,6 +4,8 @@ package Magpie::Resource::Kioku;
 
 use Moose;
 extends 'Magpie::Resource';
+with 'Magpie::Plugin::DBI';
+
 use Magpie::Constants;
 use Try::Tiny;
 use KiokuDB;
@@ -22,18 +24,6 @@ has wrapper_class => (
     default  => 'MagpieGenericWrapper',
 );
 
-has dsn => (
-    isa       => "Str",
-    is        => "ro",
-    predicate => "has_dsn",
-);
-
-has extra_args => (
-    isa       => "HashRef|ArrayRef",
-    is        => "ro",
-    predicate => "has_extra_args",
-);
-
 has typemap => (
     isa       => "KiokuDB::TypeMap",
     is        => "ro",
@@ -45,48 +35,6 @@ has _kioku_scope => (
     isa => 'KiokuDB::LiveObjects::Scope',
 );
 
-has username => (
-    is        => 'ro',
-    isa       => 'Maybe[Str]',
-    predicate => 'has_username',
-);
-
-has password => (
-    is        => 'ro',
-    isa       => 'Maybe[Str]',
-    predicate => 'has_password',
-);
-
-sub _connect_args {
-    my $self = shift;
-    my @args = ( $self->dsn || die "dsn is required" );
-
-    if ( $self->has_username ) {
-        push @args, user => $self->username;
-    }
-
-    if ( $self->has_password ) {
-        push @args, password => $self->password;
-    }
-
-    if ( $self->has_typemap ) {
-        push @args, typemap => $self->typemap;
-    }
-
-    if ( $self->has_extra_args ) {
-        my $extra = $self->extra_args;
-
-        if ( ref($extra) eq 'ARRAY' ) {
-            push @args, @$extra;
-        }
-        else {
-            push @args, %$extra;
-        }
-    }
-
-    \@args;
-}
-
 sub _build_data_source {
     my $self = shift;
     my $k    = undef;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmagpie-perl.git



More information about the Pkg-perl-cvs-commits mailing list