Skip to content

Commit

Permalink
Instead of a special snowflake _merge, use Hash::Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
symkat committed Sep 9, 2014
1 parent 191b6ef commit e6fdce5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Expand Up @@ -9,6 +9,7 @@ license 'perl';
requires 'DBIx::Class' => '0.08100';
requires 'Config::Any' => '0.23';
requires 'File::HomeDir' => '0';
requires 'Hash::Merge' => '0';

test_requires 'Test::More' => '0.42';
test_requires 'DBD::SQLite' => '0';
Expand Down
25 changes: 2 additions & 23 deletions lib/DBIx/Class/Schema/Config.pm
Expand Up @@ -5,6 +5,7 @@ use strict;
use base 'DBIx::Class::Schema';
use File::HomeDir;
use Storable qw( dclone );
use Hash::Merge qw( merge );

our $VERSION = '0.001010'; # 0.1.10
$VERSION = eval $VERSION;
Expand Down Expand Up @@ -100,28 +101,6 @@ sub get_env_vars {
return ();
}

sub _merge {
my ( $lhs, $rhs ) = @_;

if ( ref $lhs eq 'HASH' ) {
for my $key ( keys %$lhs ) {
if ( ref $lhs->{$key} eq 'HASH' ) {
$lhs->{$key} = _merge($lhs->{$key}, $rhs->{$key});
delete $rhs->{$key};
} else {
$lhs->{$key} = delete $rhs->{$key} if exists $rhs->{$key};
}
}
# Unhandled keys (simply do injection on uneven rhs structure)
for my $key ( keys %$rhs ) {
$lhs->{$key} = delete $rhs->{$key};
}
}

return $lhs;
}


# Intended to be sub-classed, the default behavior is to
# overwrite the loaded configuration with any specified
# configuration from the connect() call, with the exception
Expand All @@ -134,7 +113,7 @@ sub filter_loaded_credentials {
local $old->{user}, delete $old->{user} unless $old->{user};
local $old->{dsn}, delete $old->{dsn};

return _merge( $new, $old );
return merge( $old, $new );
};

__PACKAGE__->mk_classaccessor('config_paths');
Expand Down
1 change: 1 addition & 0 deletions t/00_load.t
Expand Up @@ -6,6 +6,7 @@ use Test::More;
my @want_modules = qw/
DBI
DBIx::Class
Hash::Merge
DBIx::Class::Schema
DBIx::Class::Schema::Config
/;
Expand Down

0 comments on commit e6fdce5

Please sign in to comment.