Fast/X.pm

filter: Statementstmt 58.8% 53 / 90 Branchbran 24.0% 13 / 54 Conditioncond 23.8% 5 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 47.0% 8 / 17 Podpod 100% 4 / 4 totaltotal 41.7% 83 / 199 CC 36 SCAR 55.3
CC
36
Cov
43%
class_for
419.0
constraint_from
7.1
throw
1.6
CRAP 251.0
↑ Summary Fast/Profile/MariaDB.pm »
1 package DBIx::Fast::X;
2  
3 34 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use Object::Pad 0.807;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 34 our $VERSION = '0.20';
7  
8 # Typed exceptions. Every object stringifies to exactly the text the plain
9 # string exception used to carry, so `$@ =~ /.../`, logs and "$@" keep
10 # working; callers that want structure test the class:
11 #
12 # if ($@ isa DBIx::Fast::X::Duplicate) { ... $@->constraint ... }
13  
14 class DBIx::Fast::X {
15 use overload
16 79 ▶ '""' => method (@) { $self->message },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 34 fallback => 1;
19  
20 79 ▶ field $message :param :reader; # full text, as a string die had
Subroutine message: called CC=1 SCAR=0.0
Pod documented
21 field $error :param :reader = undef; # the bare driver/validation text
22  
23 # JSON encoders (Mojo::JSON, Cpanel::JSON::XS convert_blessed, Minion's job
24 # results) serialize it as the plain message.
25 0 ▶ method TO_JSON () { return $message }
Subroutine TO_JSON: not called CC=1 SCAR=3.5
Subroutine error: not called CC=1 SCAR=3.5
Pod documented
Pod documented
26  
27 0 ▶ method throw :common (%args) { die $class->new(%args) }
Subroutine throw: not called CC=1 SCAR=4.6
Pod documented
28 }
29  
30 # Validation / usage errors raised by DBIx::Fast itself (Exception()).
31 34 class DBIx::Fast::X::Usage :isa(DBIx::Fast::X) { }
32  
33 # Errors reported by the database driver.
34 34 class DBIx::Fast::X::DB :isa(DBIx::Fast::X) {
35 field $code :param :reader = undef; # $DBI::err (driver error code)
36 0 ▶ field $state :param :reader = undef; # SQLSTATE
Subroutine code: not called CC=1 SCAR=2.6
37 0 ▶ field $driver :param :reader = undef; # SQLite / MariaDB / mysql / Pg
Subroutine state: not called CC=1 SCAR=2.6
38 0 ▶ field $sql :param :reader = undef; # the statement in flight
Subroutine driver: not called CC=1 SCAR=2.6
39 0 ▶ field $binds :param :reader = undef; # its bind values (arrayref)
Subroutine sql: not called CC=1 SCAR=2.6
40 0 ▶ field $constraint :param :reader = undef; # violated key/constraint name
Subroutine binds: not called CC=1 SCAR=2.6
41  
42 # Map a driver error to the most specific subclass. Codes and SQLSTATEs
43 # first; SQLite (one generic code for all constraints) by its fixed English
44 # message prefix.
45 0 ▶ sub class_for ($, $driver, $code, $state, $text) {
Subroutine class_for: called CC=31 SCAR=60.4
Subroutine constraint: not called CC=1 SCAR=2.6
46 7 ▶ $code //= '';
Condition50%1/2
$code //= ""
l!l
70
MC/DC0%0/1
$code //= ""
$code
Truth table50%1/2
A
A= $code
Aresult
11
00
47 7 ▶ $state //= '';
Condition50%1/2
$state //= ""
l!l
70
MC/DC0%0/1
$state //= ""
$state
Truth table50%1/2
A
A= $state
Aresult
11
00
48 7 ▶ $text //= '';
Condition50%1/2
$text //= ""
l!l
70
MC/DC0%0/1
$text //= ""
$text
Truth table50%1/2
A
A= $text
Aresult
11
00
49  
50 7 ▶ if ($driver eq 'MariaDB' || $driver eq 'mysql') {
Branch: 3 branches
BranchTrueFalseTotal
if ($driver eq 'MariaDB' or $driver eq 'mysql') { } 0 7 7
elsif ($driver eq 'Pg') { } 0 7 7
elsif ($driver eq 'SQLite') { } 7 0 7
Condition33%1/3
$driver eq "MariaDB" or $driver eq "mysql"
l!l&&r!l&&!r
007
MC/DC0%0/2
$driver eq "MariaDB" or $driver eq "mysql"
$driver eq "MariaDB" $driver eq "mysql"
Truth table33%1/3
A or B
A= $driver eq "MariaDB"B= $driver eq "mysql"
ABresult
1X1
011
000
51 0 ▶ return 'DBIx::Fast::X::Duplicate' if $code == 1062 || $code == 1586;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 1062 or $code == 1586 0 0 0
Condition0%0/3
$code == 1062 or $code == 1586
l!l&&r!l&&!r
000
MC/DC0%0/2
$code == 1062 or $code == 1586
$code == 1062 $code == 1586
Truth table0%0/3
A or B
A= $code == 1062B= $code == 1586
ABresult
1X1
011
000
52 0 ▶ return 'DBIx::Fast::X::ForeignKey' if $code =~ /\A(?:1216|1217|1451|1452)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $code =~ /\A(?:1216|1217|1451|1452)\z/u 0 0 0
53 0 ▶ return 'DBIx::Fast::X::NotNull' if $code == 1048 || $code == 1364;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 1048 or $code == 1364 0 0 0
Condition0%0/3
$code == 1048 or $code == 1364
l!l&&r!l&&!r
000
MC/DC0%0/2
$code == 1048 or $code == 1364
$code == 1048 $code == 1364
Truth table0%0/3
A or B
A= $code == 1048B= $code == 1364
ABresult
1X1
011
000
54 0 ▶ return 'DBIx::Fast::X::Deadlock' if $code == 1213;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 1213 0 0 0
55 0 ▶ return 'DBIx::Fast::X::LockTimeout' if $code == 1205;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 1205 0 0 0
56 0 ▶ return 'DBIx::Fast::X::Syntax' if $code == 1064;
Branch: 1 branch
BranchTrueFalseTotal
if $code == 1064 0 0 0
57 0 ▶ return 'DBIx::Fast::X::Connection' if $code =~ /\A(?:2002|2003|2006|2013|4031)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $code =~ /\A(?:2002|2003|2006|2013|4031)\z/u 0 0 0
58 }
59 elsif ($driver eq 'Pg') {
60 0 ▶ return 'DBIx::Fast::X::Duplicate' if $state eq '23505';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq 23505 0 0 0
61 0 ▶ return 'DBIx::Fast::X::ForeignKey' if $state eq '23503';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq 23503 0 0 0
62 0 ▶ return 'DBIx::Fast::X::NotNull' if $state eq '23502';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq 23502 0 0 0
63 0 ▶ return 'DBIx::Fast::X::Deadlock' if $state eq '40P01' || $state eq '40001';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "40P01" or $state eq 40001 0 0 0
Condition0%0/3
$state eq "40P01" or $state eq 40001
l!l&&r!l&&!r
000
MC/DC0%0/2
$state eq "40P01" or $state eq 40001
$state eq "40P01" $state eq 40001
Truth table0%0/3
A or B
A= $state eq "40P01"B= $state eq 40001
ABresult
1X1
011
000
64 0 ▶ return 'DBIx::Fast::X::LockTimeout' if $state eq '55P03';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "55P03" 0 0 0
65 0 ▶ return 'DBIx::Fast::X::Syntax' if $state eq '42601';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq 42601 0 0 0
66 0 ▶ return 'DBIx::Fast::X::Connection' if $state =~ /\A08/;
Branch: 1 branch
BranchTrueFalseTotal
if $state =~ /\A08/u 0 0 0
67 }
68 elsif ($driver eq 'SQLite') {
69 7 ▶ return 'DBIx::Fast::X::Duplicate'
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /UNIQUE constraint failed|PRIMARY KEY must be unique/u 0 7 7
70 if $text =~ /UNIQUE constraint failed|PRIMARY KEY must be unique/;
71 7 ▶ return 'DBIx::Fast::X::ForeignKey' if $text =~ /FOREIGN KEY constraint failed/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /FOREIGN KEY constraint failed/u 0 7 7
72 7 ▶ return 'DBIx::Fast::X::NotNull' if $text =~ /NOT NULL constraint failed/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /NOT NULL constraint failed/u 0 7 7
73 7 ▶ return 'DBIx::Fast::X::LockTimeout' if $code == 5 || $code == 6; # BUSY/LOCKED
Branch: 1 branch
BranchTrueFalseTotal
if $code == 5 or $code == 6 0 7 7
Condition33%1/3
$code == 5 or $code == 6
l!l&&r!l&&!r
007
MC/DC0%0/2
$code == 5 or $code == 6
$code == 5 $code == 6
Truth table33%1/3
A or B
A= $code == 5B= $code == 6
ABresult
1X1
011
000
74 7 ▶ return 'DBIx::Fast::X::Syntax' if $text =~ /syntax error/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /syntax error/u 0 7 7
75 }
76 7 return 'DBIx::Fast::X::DB';
77 }
78  
79 # The violated key / constraint name, when the driver message carries it.
80 7 ▶ sub constraint_from ($, $text) {
Subroutine constraint_from: called CC=6 SCAR=19.6
81 7 ▶ return undef unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 7 7
82 7 ▶ return $1 if $text =~ /for key '([^']+)'/; # MySQL/MariaDB
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /for key '([^']+)'/u 0 7 7
83 7 ▶ return $1 if $text =~ /(?:unique|foreign key|check) constraint "([^"]+)"/; # Pg
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /(?:unique|foreign key|check) constraint "([^"]+)"/u 0 7 7
84 7 ▶ return $1 if $text =~ /(?:UNIQUE|NOT NULL) constraint failed: (\S+)/; # SQLite
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /(?:UNIQUE|NOT NULL) constraint failed: (\S+)/u 0 7 7
85 7 ▶ return $1 if $text =~ /FOREIGN KEY \(`?([^`)]+)`?\)/; # MySQL FK column
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /FOREIGN KEY \(`?([^`)]+)`?\)/u 0 7 7
86 7 return undef;
87 }
88 }
89  
90 34 class DBIx::Fast::X::Duplicate :isa(DBIx::Fast::X::DB) { }
91 34 class DBIx::Fast::X::ForeignKey :isa(DBIx::Fast::X::DB) { }
92 34 class DBIx::Fast::X::NotNull :isa(DBIx::Fast::X::DB) { }
93 34 class DBIx::Fast::X::Deadlock :isa(DBIx::Fast::X::DB) { }
94 34 class DBIx::Fast::X::LockTimeout :isa(DBIx::Fast::X::DB) { }
95 34 class DBIx::Fast::X::Syntax :isa(DBIx::Fast::X::DB) { }
96 34 class DBIx::Fast::X::Connection :isa(DBIx::Fast::X::DB) { }
97  
98 34 1;
99  
100 __END__
↑ Summary Fast/Profile/MariaDB.pm »