line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Load::Util; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
132853
|
use strict; |
|
8
|
|
|
|
|
33
|
|
|
8
|
|
|
|
|
283
|
|
4
|
8
|
|
|
8
|
|
42
|
use warnings; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
282
|
|
5
|
8
|
|
|
|
|
473
|
use String::CamelCase qw/ |
6
|
|
|
|
|
|
|
camelize |
7
|
|
|
|
|
|
|
decamelize |
8
|
8
|
|
|
8
|
|
3673
|
/; |
|
8
|
|
|
|
|
4534
|
|
9
|
8
|
|
|
8
|
|
52
|
use base qw/Exporter/; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
4372
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
12
|
|
|
|
|
|
|
name_list |
13
|
|
|
|
|
|
|
parse |
14
|
|
|
|
|
|
|
remove_extension |
15
|
|
|
|
|
|
|
trim |
16
|
|
|
|
|
|
|
/; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub name_list { |
19
|
164
|
|
|
164
|
1
|
13132
|
my $name = shift; |
20
|
|
|
|
|
|
|
|
21
|
164
|
|
|
|
|
201
|
my @list; |
22
|
|
|
|
|
|
|
|
23
|
164
|
|
|
|
|
254
|
$name = remove_extension($name); |
24
|
|
|
|
|
|
|
|
25
|
164
|
|
|
|
|
320
|
$name =~ s/-/_/xg; |
26
|
164
|
|
|
|
|
337
|
push @list, camelize $name; |
27
|
|
|
|
|
|
|
|
28
|
164
|
|
|
|
|
2021
|
$name = decamelize $name; |
29
|
164
|
|
|
|
|
1541
|
push @list, $name; |
30
|
|
|
|
|
|
|
|
31
|
164
|
|
|
|
|
309
|
$name =~ s/_/-/xg; |
32
|
164
|
|
|
|
|
251
|
push @list, $name; |
33
|
|
|
|
|
|
|
|
34
|
164
|
100
|
|
|
|
509
|
return wantarray ? @list : \@list; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub parse { |
38
|
32
|
|
|
32
|
1
|
7587
|
my $content = shift; |
39
|
32
|
|
|
|
|
45
|
my $end = shift; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# get all sql by name |
42
|
32
|
|
|
|
|
384
|
my (@data) = $content =~ /--\s*(?:#|\[|\()\s*([\w-]+)\s*(?:|]|\))\n([^;]+;)/g; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# get all sql without name |
45
|
32
|
100
|
|
|
|
84
|
unless (@data) { |
46
|
12
|
|
|
|
|
126
|
my (@list) = $content =~ /([^;]+;)/g; |
47
|
|
|
|
|
|
|
|
48
|
12
|
|
|
|
|
23
|
my $num = 1; |
49
|
12
|
|
|
|
|
22
|
for my $sql (@list) { |
50
|
31
|
|
|
|
|
57
|
push(@data, $num++); |
51
|
31
|
|
|
|
|
66
|
push(@data, trim($sql)); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# if got one or nothing, set content as default |
55
|
12
|
50
|
|
|
|
39
|
unless (@data) { |
56
|
0
|
|
|
|
|
0
|
push(@data, 'default'); |
57
|
0
|
|
|
|
|
0
|
push(@data, trim($content)); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
32
|
100
|
|
|
|
74
|
if (defined $end) { |
62
|
2
|
|
|
|
|
10
|
for my $sql (@data) { |
63
|
18
|
|
|
|
|
42
|
$sql =~ s/;$/${end}/s; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
32
|
50
|
|
|
|
199
|
return wantarray ? @data : \@data; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub remove_extension { |
71
|
195
|
|
|
195
|
1
|
4131
|
my $value = shift; |
72
|
|
|
|
|
|
|
|
73
|
195
|
50
|
|
|
|
502
|
$value =~ s/\.sql$//i if $value; |
74
|
|
|
|
|
|
|
|
75
|
195
|
|
|
|
|
368
|
return $value; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub trim { |
79
|
35
|
|
|
35
|
1
|
1414
|
my $value = shift; |
80
|
|
|
|
|
|
|
|
81
|
35
|
|
|
|
|
694
|
$value =~ s/^\s+|\s+$//g; |
82
|
|
|
|
|
|
|
|
83
|
35
|
|
|
|
|
85
|
return $value; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |