line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Simple::DataSection; |
2
|
4
|
|
|
4
|
|
2437
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
188
|
|
3
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
144
|
|
4
|
4
|
|
|
4
|
|
44
|
use base 'DBIx::Simple'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
8253
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
136831
|
use Carp; |
|
4
|
|
|
|
|
1527
|
|
|
4
|
|
|
|
|
2194
|
|
8
|
4
|
|
|
4
|
|
4130
|
use Data::Section::Simple; |
|
4
|
|
|
|
|
2363
|
|
|
4
|
|
|
|
|
1712
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
1
|
|
my $package = scalar caller; |
12
|
0
|
|
|
|
|
|
my $self = shift->SUPER::new(@_); |
13
|
0
|
|
|
|
|
|
$self->force_utf8(); |
14
|
0
|
|
|
|
|
|
$self->{package} = $package; |
15
|
0
|
|
|
|
|
|
$self->_init; |
16
|
0
|
|
|
|
|
|
$self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub force_utf8 { |
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
21
|
0
|
0
|
|
|
|
|
return unless $self->{dbd}; |
22
|
0
|
|
|
|
|
|
my $driver_name = $self->{dbd}; |
23
|
0
|
0
|
|
|
|
|
if ( $driver_name eq 'Pg' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$self->{dbh}->{pg_enable_utf8} = 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ( $driver_name eq 'mysql' ) { |
27
|
0
|
|
|
|
|
|
$self->{dbh}->{mysql_enable_utf8} = 1; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
elsif ( $driver_name eq 'SQLite' ) { |
30
|
0
|
|
|
|
|
|
$self->{dbh}->{unicode} = 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub connect { |
35
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::connect(@_); |
36
|
0
|
|
|
|
|
|
$self->force_utf8(); |
37
|
0
|
|
0
|
|
|
|
$self->{package} ||= scalar caller(0); |
38
|
0
|
|
|
|
|
|
$self->_init; |
39
|
0
|
|
|
|
|
|
$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _init { |
43
|
0
|
|
|
0
|
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
$self->{section} = Data::Section::Simple->new( $self->{package} ); |
45
|
0
|
|
|
|
|
|
$self->{cache} = {}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub query_by_sql { |
49
|
0
|
|
|
0
|
0
|
|
my ( $self, $sql_name, @binds ) = @_; |
50
|
0
|
|
|
|
|
|
my $query = $self->get_sql($sql_name); |
51
|
0
|
|
|
|
|
|
$self->SUPER::query( $query, @binds ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_sql { |
55
|
0
|
|
|
0
|
0
|
|
my ( $self, $sql_name ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ( my $sql = $self->{cache}{$sql_name} ) { |
58
|
0
|
|
|
|
|
|
return $sql; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
my $sql = $self->{section}->get_data_section($sql_name); |
61
|
0
|
0
|
|
|
|
|
if ($sql) { |
62
|
0
|
0
|
|
|
|
|
$self->{cache}{$sql_name} = $sql if $self->{use_cache}; |
63
|
0
|
|
|
|
|
|
return $sql; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
croak "could not find sql: $sql_name in __DATA__ section"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |