File: Util.pm

package info (click to toggle)
libdbix-class-helpers-perl 2.036000-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,008 kB
  • sloc: perl: 5,041; sql: 537; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 1,054 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package A::Util;

use strict;
use warnings;

use TestSchema;

sub connect {
   my ($engine, $storage_type, $on_connect_call) = @_;

   my $schema = 'TestSchema';
   $schema->storage_type('DBIx::Class::Storage::DBI'); # class methods: THE WORST
   $schema->storage_type('DBIx::Class::Storage::DBI::' . $storage_type)
      if $storage_type && !connected($engine, $on_connect_call);

   $schema = TestSchema->connect(@{connect_info($engine, $on_connect_call)});
   $schema->deploy if connected($engine, $on_connect_call);
   $schema->storage->dbh->{private_dbii_driver} = $engine;

   $schema
}

sub env {
   my $engine = shift;

   my $p = 'DBIITEST_' . uc($engine);
   $p . '_DSN', $p . '_USER', $p . '_PASSWORD';
}

sub connect_info {
   my ($engine, $on_connect_call) = @_;

   my @connect_info = grep $_, map $ENV{$_}, env($engine);
   push @connect_info, { on_connect_call => $on_connect_call }
      if @connect_info && $on_connect_call;

   return \@connect_info;
}

sub connected {
   return 1 if $_[0] eq 'SQLite';
   !!@{connect_info(@_)}
}

1;