MySQL/Adapter.pm

filter: Statementstmt 85.7% 24 / 28 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 2 totaltotal 66.6% 38 / 57 CC 8 SCAR 16.7
CC
8
Cov
75%
to_native
7.6
no_charset_for
6.0
BEGIN
1.0
CRAP 5.3
« MySQL/Introspect/ForeignKeys.pm ↑ Summary MySQL/Diff/ForeignKey.pm »
1 package DBIO::MySQL::Adapter;
2 # ABSTRACT: MySQL base->native type resolver
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use base 'DBIO::Adapter::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 my %NATIVE = (
10 integer => 'BIGINT',
11 text => 'LONGTEXT',
12 boolean => 'TINYINT(1)',
13 double => 'DOUBLE',
14 blob => 'LONGBLOB',
15 timestamp => 'DATETIME',
16 );
17  
18 # Native types whose information_schema row reports character_set_name and
19 # collation_name as NULL (binary, numeric, datetime families). Text families
20 # (CHAR, VARCHAR, LONGTEXT, …) get a server-assigned charset and we do not
21 # preserve that on round-trip -- see DBIO::MySQL::Diff ESCALATION NOTE.
22 5 my %NO_CHARSET = map { $_ => 1 } qw(
23 bigint tinyint double decimal longblob datetime
24 );
25  
26 9 ▶sub to_native {
Subroutine to_native: called CC=7 SCAR=20.2
Pod undocumented
27 9 my ($self, $col) = @_;
28 9 my $b = $col->{base_type};
29 9 ▶ return 'CHAR(' . ($col->{size} // 255) . ')' if $b eq 'char';
Branch: 1 branch
BranchTrueFalseTotal
if $b eq "char" 1 8 9
Condition50%1/2
$col->{"size"} // 255
l!l
10
MC/DC0%0/1
$col->{"size"} // 255
$col->{"size"}
Truth table50%1/2
A
A= $col->{"size"}
Aresult
11
00
30 8 ▶ if ($b eq 'numeric') {
Branch: 1 branch
BranchTrueFalseTotal
if ($b eq "numeric") 1 7 8
31 1 my ($p, $s) = @{$col}{qw/precision scale/};
32 1 ▶ return (defined $p && defined $s) ? "DECIMAL($p,$s)" : 'DECIMAL';
Branch: 1 branch
BranchTrueFalseTotal
defined $p && defined $s ? : 1 0 1
Condition33%1/3
defined $p and defined $s
!ll&&!rl&&r
001
MC/DC0%0/2
defined $p and defined $s
defined $p defined $s
Truth table33%1/3
A and B
A= defined $pB= defined $s
ABresult
0X0
100
111
33 }
34 7 ▶ return $NATIVE{$b} // croak "no MySQL native type for base '$b'";
Condition66%2/3
$NATIVE{$b} // croak("no MySQL native type for base '${b}'")
l!l&&r!l&&!r
610
MC/DC0%0/2
$NATIVE{$b} // croak("no MySQL native type for base '${b}'")
$NATIVE{$b} croak("no MySQL native type for base '${b}'")
Truth table33%1/3
A // B
A= $NATIVE{$b}B= croak("no MySQL native type for base '${b}'")
ABresult
1X1
011
000
35 }
36  
37 # True when the given native type (e.g. "BIGINT", "DECIMAL(10,2)", "DATETIME")
38 # is from a family whose information_schema row never carries a character
39 # set / collation. Used by Diff::target_from_compiled to leave those fields
40 # undef on the target side of the comparison.
41 0 ▶sub no_charset_for {
Subroutine no_charset_for: not called CC=2 SCAR=17.9
Pod undocumented
42 0 my ($self, $native) = @_;
43 0 my $lc = lc $native;
44 0 $lc =~ s/\(.*//; # strip "(10,2)" parameters
45 0 ▶ return exists $NO_CHARSET{$lc} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $NO_CHARSET{$lc} ? : 0 0 0
46 }
47  
48 # capabilities inherited from DBIO::Adapter::Base: supports_alter_column_type => 1
49  
50 5 1;
51  
52 __END__
53  
54 =pod
55  
56 =encoding UTF-8
57  
58 =head1 NAME
59  
60 DBIO::MySQL::Adapter - MySQL base->native type resolver
61  
62 =head1 VERSION
63  
64 version 0.900001
65  
66 =head1 AUTHOR
67  
68 DBIO & DBIx::Class Authors
69  
70 =head1 COPYRIGHT AND LICENSE
71  
72 Copyright (C) 2026 DBIO Authors
73 Portions Copyright (C) 2005-2025 DBIx::Class Authors
74 Based on DBIx::Class, heavily modified.
75  
76 This is free software; you can redistribute it and/or modify it under
77 the same terms as the Perl 5 programming language system itself.
78  
79 =cut
« MySQL/Introspect/ForeignKeys.pm ↑ Summary MySQL/Diff/ForeignKey.pm »