Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.07 KB | None | 0 0
  1. package NADS::Schema;
  2.  
  3. use utf8;
  4. use Moose;
  5. use MooseX::Types::Moose qw/Str/;
  6.  
  7. use Data::Dumper;
  8.  
  9. extends 'DBIx::Class::Schema';
  10.  
  11. our $VERSION = 1;
  12.  
  13. __PACKAGE__->load_namespaces;
  14. __PACKAGE__->load_components('DeploymentHandler::VersionStorage::Standard::Component');
  15.  
  16. has 'fs_datadir' => (
  17.     is  => 'rw',
  18.     isa => Str,
  19. );
  20.  
  21. around connection => sub {
  22.     my $orig = shift;
  23.     my ($self, $connect_info) = @_;
  24.  
  25.     return $self if !defined($connect_info->{attributes});
  26.  
  27.     my $attributes = delete $connect_info->{attributes};
  28.  
  29.     $self = $self->$orig($connect_info);
  30.  
  31.     foreach my $key ( keys %$attributes )
  32.     {
  33.         if($self->can($key))
  34.         {
  35.             $self->$key($attributes->{$key});
  36.         }
  37.     }
  38.     $self
  39. };
  40.  
  41. sub connect_config {
  42.     my ($self, $config) = @_;
  43.     return $self->connect({
  44.         dsn => $config->database->dsn,
  45.         username => $config->database->username,
  46.         password => $config->database->password,
  47.         %{ $config->database->args },
  48.         %{ $config->database->attributes },
  49.     });
  50. }
  51.  
  52. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement