DBIx-Custom / xt / dbix-connector.t /
Newer Older
63 lines | 1.323kb
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1
use Test::More 'no_plan';
2

            
3
{
4
     package MyDBI1;
5
     
6
     use base 'DBIx::Custom';
7
     
8
     use DBIx::Connector;
9
     
10
     __PACKAGE__->attr(connection_manager => sub {
11
         my $self = shift;
12
         
13
         my $cm = DBIx::Connector->new(
14
             $self->data_source,
15
             $self->user,
16
             $self->password,
17
             {
18
                 %{$self->default_dbi_option},
19
                 %{$self->dbi_option}
20
             }
21
         );
22
         
23
         return $cm
24
     });
25
     
26
     sub dbh { shift->connection_manager->dbh }
27
     
28
     sub connect {
29
         my $self = shift->SUPER::new(@_);
30
         
31
         return $self;
32
     }
33
}
34

            
35
# user password database
36
our ($USER, $PASSWORD, $DATABASE) = connect_info();
37

            
38
# Functions for tests
39
sub connect_info {
40
    my $file = 'password.tmp';
41
    open my $fh, '<', $file
42
      or return;
43
    
44
    my ($user, $password, $database) = split(/\s/, (<$fh>)[0]);
45
    
46
    close $fh;
47
    
48
    return ($user, $password, $database);
49
}
50

            
51
my $dbi = MyDBI1->connect(
52
    user => $USER, password => $PASSWORD,
53
    data_source => "dbi:mysql:database=$DATABASE");
54

            
55
$dbi->delete_all(table => 'table1');
56
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
57
is_deeply($dbi->select(table => 'table1')->fetch_hash_all, [{key1 => 1, key2 => 2}]);
58

            
59

            
60

            
61

            
62

            
63