Load/Util.pm

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