line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ActiveRecord::Simple::Utils; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
60
|
use strict; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
261
|
|
4
|
12
|
|
|
12
|
|
65
|
use warnings; |
|
12
|
|
|
|
|
16
|
|
|
12
|
|
|
|
|
323
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
4568
|
use Module::Load; |
|
12
|
|
|
|
|
10474
|
|
|
12
|
|
|
|
|
60
|
|
9
|
12
|
|
|
12
|
|
4335
|
use Module::Loaded; |
|
12
|
|
|
|
|
6012
|
|
|
12
|
|
|
|
|
544
|
|
10
|
|
|
|
|
|
|
|
11
|
12
|
|
|
12
|
|
74
|
use Scalar::Util qw/blessed/; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
4724
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw/Exporter/; |
14
|
|
|
|
|
|
|
our @EXPORT = qw/class_to_table_name all_blessed load_module/; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub quote_sql_stmt { |
18
|
12
|
|
|
12
|
0
|
47
|
my ($sql, $driver_name) = @_; |
19
|
|
|
|
|
|
|
|
20
|
12
|
50
|
33
|
|
|
44
|
return unless $sql && $driver_name; |
21
|
|
|
|
|
|
|
|
22
|
12
|
|
50
|
|
|
31
|
$driver_name //= 'Pg'; |
23
|
12
|
|
|
|
|
36
|
my $quotes_map = { |
24
|
|
|
|
|
|
|
Pg => q/"/, |
25
|
|
|
|
|
|
|
mysql => q/`/, |
26
|
|
|
|
|
|
|
SQLite => q/`/, |
27
|
|
|
|
|
|
|
}; |
28
|
12
|
|
|
|
|
19
|
my $quote = $quotes_map->{$driver_name}; |
29
|
|
|
|
|
|
|
|
30
|
12
|
|
|
|
|
57
|
$sql =~ s/"/$quote/g; |
31
|
|
|
|
|
|
|
|
32
|
12
|
|
|
|
|
49
|
return $sql; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub class_to_table_name { |
36
|
41
|
|
|
41
|
0
|
67
|
my ($class) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#load $class; |
39
|
|
|
|
|
|
|
|
40
|
41
|
100
|
|
|
|
626
|
return $class->_get_table_name if $class->can('_get_table_name'); |
41
|
|
|
|
|
|
|
|
42
|
11
|
|
|
|
|
27
|
$class =~ s/.*:://; |
43
|
|
|
|
|
|
|
#$class_name = lc $class_name; |
44
|
11
|
|
|
|
|
58
|
my $table_name = join('_', map {lc} grep {length} split /([A-Z]{1}[^A-Z]*)/, $class); |
|
11
|
|
|
|
|
44
|
|
|
22
|
|
|
|
|
43
|
|
45
|
|
|
|
|
|
|
|
46
|
11
|
|
|
|
|
30
|
return $table_name; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub is_integer { |
50
|
0
|
|
|
0
|
0
|
0
|
my ($data_type) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
0
|
return unless $data_type; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
return grep { $data_type eq $_ } qw/integer bigint tinyint int smallint/; |
|
0
|
|
|
|
|
0
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub is_numeric { |
58
|
0
|
|
|
0
|
0
|
0
|
my ($data_type) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
0
|
return unless $data_type; |
61
|
0
|
0
|
|
|
|
0
|
return 1 if is_integer($data_type); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
return grep { $data_type eq $_ } qw/numeric decimal/; |
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub all_blessed { |
67
|
9
|
|
|
9
|
0
|
15
|
my ($list) = @_; |
68
|
|
|
|
|
|
|
|
69
|
9
|
|
|
|
|
15
|
for my $item (@$list) { |
70
|
9
|
50
|
|
|
|
24
|
return unless defined $item; |
71
|
9
|
100
|
|
|
|
36
|
return unless blessed $item; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
16
|
return 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub load_module { |
78
|
37
|
|
|
37
|
0
|
58
|
my ($module_name) = @_; |
79
|
|
|
|
|
|
|
|
80
|
37
|
100
|
|
|
|
81
|
if (!is_loaded $module_name) { |
81
|
15
|
|
|
|
|
293
|
eval { load $module_name; }; |
|
15
|
|
|
|
|
45
|
|
82
|
15
|
|
|
|
|
4044
|
mark_as_loaded $module_name; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |