blib/lib/DBIO/MySQL/DefaultValue.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 24 / 24 Conditioncond 69.2% 9 / 13 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 92.0% 93 / 101 CC 18 SCAR 18.9
CC
18
Cov
95%
catalog_default
11.0
default_sql
4.0
on_update_sql
3.0
CRAP 6.6
« blib/lib/DBIO/MySQL/Introspect.pm ↑ Summary blib/lib/DBIO/MySQL/Diff/PrimaryKey.pm »
1 package DBIO::MySQL::DefaultValue;
2 # ABSTRACT: MySQL/MariaDB DEFAULT values for generated DDL, written and read
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 Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 88 our @EXPORT_OK = qw(default_sql catalog_default catalog_on_update on_update_sql);
12  
13  
14  
15 # The spellings of "now" both servers take as a column default without
16 # parentheses (and as ON UPDATE).
17 88 my $NOW = qr/\A(?:current_timestamp|now|localtime|localtimestamp)(?:\(\s*\d*\s*\))?\z/i;
18  
19 34 ▶sub default_sql {
Subroutine default_sql: called CC=4 SCAR=13.9
Pod documented
20 34 my ($value, $is_expression) = @_;
21  
22 34 ▶ return $$value if ref $value eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "SCALAR" 3 31 34
23  
24 31 ▶ if ($is_expression) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_expression) 11 20 31
25 11 ▶ return $value =~ $NOW ? $value : "($value)";
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /$NOW/ ? : 10 1 11
26 }
27  
28 20 (my $lit = $value) =~ s/\\/\\\\/g;
29 20 $lit =~ s/'/''/g;
30 20 $lit =~ s/\0/\\0/g;
31 20 return "'$lit'";
32 }
33  
34  
35 78 ▶sub catalog_default {
Subroutine catalog_default: called CC=11 SCAR=24.0
Pod documented
36 78 my (%a) = @_;
37 78 my $raw = $a{raw};
38 78 ▶ return (undef, 0) unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 32 46 78
39  
40 46 ▶ if ($a{mariadb_expression}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a{"mariadb_expression"}) 23 23 46
41 23 ▶ if ($raw =~ /\A'(.*)'\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\A'(.*)'\z/s) 12 11 23
42 12 my $lit = $1;
43 12 my %esc = (n => "\n", r => "\r", t => "\t", 0 => "\0", Z => "\x1a", b => "\b");
44 12 $lit =~ s/''/'/g;
45 12 ▶ $lit =~ s/\\(.)/exists $esc{$1} ? $esc{$1} : $1/gse;
Branch: 1 branch
BranchTrueFalseTotal
exists $esc{$1} ? : 1 1 2
46 12 return ($lit, 0);
47 }
48 11 ▶ return ($raw, 0) if $raw =~ /\A[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /\A[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?\z/ 3 8 11
49 8 return ($raw, 1);
50 }
51  
52 23 ▶ if (($a{extra} // '') =~ /\bDEFAULT_GENERATED\b/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (($a{"extra"} // "") =~ /\bDEFAULT_GENERATED\b/i) 8 15 23
Condition50%1/2
$a{"extra"} // ""
l!l
230
MC/DC0%0/1
$a{"extra"} // ""
$a{"extra"}
Truth table50%1/2
A
A= $a{"extra"}
Aresult
11
00
53 8 (my $expr = $raw) =~ s/\\'/'/g;
54 8 return ($expr, 1);
55 }
56  
57 return ($raw, 1)
58 15 ▶ if $raw =~ $NOW && ($a{data_type} // '') =~ /\A(?:timestamp|datetime)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /$NOW/ and ($a{"data_type"} // "") =~ /\A(?:timestamp|datetime)\z/i 1 14 15
Condition80%4/5
$raw =~ /$NOW/ and ($a{"data_type"} // "") =~ /\A(?:timestamp|datetime)\z/i
!ll&&!rl&&r
1221
$a{"data_type"} // ""
l!l
30
MC/DC50%1/2
$raw =~ /$NOW/ and ($a{"data_type"} // "") =~ /\A(?:timestamp|datetime)\z/i
$raw =~ /$NOW/ $a{"data_type"}
Truth table66%2/3
A and B
A= $raw =~ /$NOW/B= $a{"data_type"}
ABresult
0X0
100
111
59  
60 14 return ($raw, 0);
61 }
62  
63  
64 78 ▶sub catalog_on_update {
Subroutine catalog_on_update: called CC=3 SCAR=11.0
Pod documented
65 78 my ($extra) = @_;
66 78 ▶ return undef unless defined $extra && $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extra and $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i 72 6 78
Condition66%2/3
defined $extra and $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
!ll&&!rl&&r
0726
MC/DC50%1/2
defined $extra and $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
defined $extra $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
Truth table66%2/3
A and B
A= defined $extraB= $extra =~ /\bon\s+update\s+(\w+(?:\(\s*\d*\s*\))?)/i
ABresult
0X0
100
111
67 6 (my $expr = uc $1) =~ s/\s+//g;
68 6 $expr =~ s/\(\)\z//;
69 6 return $expr;
70 }
71  
72  
73 192 ▶sub on_update_sql {
Subroutine on_update_sql: called CC=3 SCAR=11.1
Pod documented
74 192 my ($on_update) = @_;
75 192 ▶ return defined $on_update && length $on_update ? " ON UPDATE $on_update" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $on_update && length $on_update ? : 5 187 192
Condition66%2/3
defined $on_update and length $on_update
!ll&&!rl&&r
18705
MC/DC50%1/2
defined $on_update and length $on_update
defined $on_update length $on_update
Truth table66%2/3
A and B
A= defined $on_updateB= length $on_update
ABresult
0X0
100
111
76 }
77  
78 88 1;
79  
80 __END__
« blib/lib/DBIO/MySQL/Introspect.pm ↑ Summary blib/lib/DBIO/MySQL/Diff/PrimaryKey.pm »