blib/lib/DBIO/MySQL/Identifier.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 12 / 12 Conditioncond 70.0% 14 / 20 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 88.8% 80 / 90 CC 14 SCAR 15.1
CC
14
Cov
91%
split_table_name
7.1
check_table_name
6.1
quote_table
2.0
CRAP 4.5
« blib/lib/DBIO/MySQL/Adapter.pm ↑ Summary blib/lib/DBIO/MySQL/MariaDBForkGuard.pm »
1 package DBIO::MySQL::Identifier;
2 # ABSTRACT: MySQL/MariaDB identifier quoting for generated DDL
3  
4 88 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 88 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 88 our $VERSION = '0.900007';
8  
9 88 ▶use DBIO::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 88 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 88 our @EXPORT_OK = qw(quote_ident check_table_name split_table_name quote_table quote_table_in);
13  
14  
15  
16 2089 ▶sub quote_ident {
Subroutine quote_ident: called CC=1 SCAR=0.0
Pod documented
17 2089 my ($name) = @_;
18 2089 $name =~ s/`/``/g;
19 2089 return "`$name`";
20 }
21  
22  
23 403 ▶sub split_table_name {
Subroutine split_table_name: called CC=7 SCAR=19.7
Pod documented
24 403 my ($name) = @_;
25 403 ▶ return (undef, $name) unless defined $name && !ref $name && $name =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and not ref $name and $name =~ /\./ 375 28 403
Condition50%3/6
defined $name and not ref $name and $name =~ /\./
!ll&&!rl&&r
037528
defined $name and not ref $name
!ll&&!rl&&r
00403
MC/DC33%1/3
defined $name and not ref $name and $name =~ /\./
defined $name not ref $name $name =~ /\./
Truth table50%2/4
A and not(B) and C
A= defined $nameB= not ref $nameC= $name =~ /\./
ABCresult
0XX0
10X0
1100
1111
26 28 my @parts = split /\./, $name, -1;
27 28 ▶ DBIO::Exception->throw("DBIO::MySQL: table '$name' is refused: a table name "
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 2 and length $parts[0] and length $parts[1] 3 25 28
Condition100%6/6
@parts == 2 and length $parts[0] and length $parts[1]
!ll&&!rl&&r
2125
@parts == 2 and length $parts[0]
!ll&&!rl&&r
1126
MC/DC100%3/3
@parts == 2 and length $parts[0] and length $parts[1]
@parts == 2 length $parts[0] length $parts[1]
Truth table100%4/4
A and B and C
A= @parts == 2B= length $parts[0]C= length $parts[1]
ABCresult
0XX0
10X0
1100
1111
28 . 'is table or database.table, with both halves given and one dot')
29 unless @parts == 2 && length $parts[0] && length $parts[1];
30 25 return @parts;
31 }
32  
33  
34 169 ▶sub quote_table {
Subroutine quote_table: called CC=2 SCAR=6.9
Pod documented
35 169 my ($database, $table) = split_table_name($_[0]);
36 169 ▶ return defined $database ? quote_ident($database) . '.' . quote_ident($table) : quote_ident($table);
Branch: 1 branch
BranchTrueFalseTotal
defined $database ? : 7 162 169
37 }
38  
39  
40 314 ▶sub quote_table_in {
Subroutine quote_table_in: called CC=2 SCAR=6.9
Pod documented
41 314 my ($database, $table) = @_;
42 314 ▶ return defined $database ? quote_ident($database) . '.' . quote_ident($table) : quote_ident($table);
Branch: 1 branch
BranchTrueFalseTotal
defined $database ? : 6 308 314
43 }
44  
45  
46 192 ▶sub check_table_name {
Subroutine check_table_name: called CC=6 SCAR=18.2
Pod documented
47 192 my ($name, $kind) = @_;
48 192 ▶ return $name unless defined $name && !ref $name && $name =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and not ref $name and $name =~ /\./ 180 12 192
Condition50%3/6
defined $name and not ref $name and $name =~ /\./
!ll&&!rl&&r
018012
defined $name and not ref $name
!ll&&!rl&&r
00192
MC/DC33%1/3
defined $name and not ref $name and $name =~ /\./
defined $name not ref $name $name =~ /\./
Truth table50%2/4
A and not(B) and C
A= defined $nameB= not ref $nameC= $name =~ /\./
ABCresult
0XX0
10X0
1100
1111
49 12 ▶ $kind //= 'table';
Condition100%2/2
$kind //= "table"
l!l
111
MC/DC100%1/1
$kind //= "table"
$kind
Truth table100%2/2
A
A= $kind
Aresult
11
00
50 12 ▶ if ($kind ne 'table') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind ne "table") 1 11 12
51 1 DBIO::Exception->throw("DBIO::MySQL: $kind '$name' is refused: a name with a "
52 . "dot means database.table to MySQL, and creating a $kind in another "
53 . "database is not supported. Name the $kind without a dot");
54 }
55 11 split_table_name($name);
56 8 return $name;
57 }
58  
59 88 1;
60  
61 __END__
« blib/lib/DBIO/MySQL/Adapter.pm ↑ Summary blib/lib/DBIO/MySQL/MariaDBForkGuard.pm »