Load/Util.pm

filter: Statementstmt 95.6% 44 / 46 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 92.8% 65 / 70 SCAR 22.0
CC
9
Cov
91%
parse
7.2
remove_extension
2.0
name_list
2.0
CRAP 9.1
« Load/Method.pm ↑ Summary
1 package SQL::Load::Util;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 use String::CamelCase qw/
6 camelize
7 decamelize
8 8 ▶/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 8 our @EXPORT_OK = qw/
12 name_list
13 parse
14 remove_extension
15 trim
16 /;
17  
18 sub name_list {
19 164 ▶ my $name = shift;
Subroutine name_list: called CC=2 SCAR=6.9
Pod documented
20
21 164 my @list;
22
23 164 $name = remove_extension($name);
24
25 164 $name =~ s/-/_/xg;
26 164 push @list, camelize $name;
27
28 164 $name = decamelize $name;
29 164 push @list, $name;
30
31 164 $name =~ s/_/-/xg;
32 164 push @list, $name;
33
34 164 ▶ return wantarray ? @list : \@list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 149 15 164
35 }
36  
37 sub parse {
38 32 ▶ my $content = shift;
Subroutine parse: called CC=7 SCAR=19.8
Pod documented
39 32 my $end = shift;
40
41 # get all sql by name
42 32 my (@data) = $content =~ /--\s*(?:#|\[|\()\s*([\w-]+)\s*(?:|]|\))\n([^;]+;)/g;
43
44 # get all sql without name
45 32 ▶ unless (@data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@data) 12 20 32
46 12 my (@list) = $content =~ /([^;]+;)/g;
47
48 12 my $num = 1;
49 12 for my $sql (@list) {
50 31 push(@data, $num++);
51 31 push(@data, trim($sql));
52 }
53
54 # if got one or nothing, set content as default
55 12 ▶ unless (@data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@data) 0 12 12
56 0 push(@data, 'default');
57 0 push(@data, trim($content));
58 }
59 }
60
61 32 ▶ if (defined $end) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $end) 2 30 32
62 2 for my $sql (@data) {
63 18 $sql =~ s/;$/${end}/s;
64 }
65 }
66
67 32 ▶ return wantarray ? @data : \@data;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 32 0 32
68 }
69  
70 sub remove_extension {
71 195 ▶ my $value = shift;
Subroutine remove_extension: called CC=2 SCAR=7.1
Pod documented
72
73 195 ▶ $value =~ s/\.sql$//i if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 195 0 195
74
75 195 return $value;
76 }
77  
78 sub trim {
79 35 ▶ my $value = shift;
Subroutine trim: called CC=1 SCAR=0.0
Pod documented
80
81 35 $value =~ s/^\s+|\s+$//g;
82
83 35 return $value;
84 }
85  
86 8 1;
87  
88 __END__
« Load/Method.pm ↑ Summary