| 1 | package DBIO::MySQL::Introspect::Util; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Shared helpers for the MySQL/MariaDB introspect submodules | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub keep_table { | ||||||||||||||||||||||||||
|
Subroutine
keep_table: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 0 | my ($class, $tables, $name) = @_; | |||||||||||||||||||||||||||
| 11 | 0 | ▶ | return exists $tables->{ $name // '' } ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$name // ""
MC/DC0%0/1
$name // ""
$name
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub column_size { | ||||||||||||||||||||||||||
|
Subroutine
column_size: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ($class, $column_type) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | ▶ | return undef unless defined $column_type && length $column_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $column_type and length $column_type
MC/DC0%0/2
defined $column_type and length $column_type
defined $column_type
length $column_type
Truth table0%0/3
A and B
A= defined $column_typeB= length $column_type
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if ($column_type =~ /^\w+\s*\(\s*(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | return $1 + 0; # numericify | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 0 | return undef; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4 | 1; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | __END__ | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =pod | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 NAME | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | DBIO::MySQL::Introspect::Util - Shared helpers for the MySQL/MariaDB introspect submodules | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 VERSION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | version 0.900001 | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Leaf module holding the pure-data helpers shared by the per-section | ||||||||||||||||||||||||||||
| 43 | information_schema readers | ||||||||||||||||||||||||||||
| 44 | (L<DBIO::MySQL::Introspect::Columns>, L<DBIO::MySQL::Introspect::Indexes>, | ||||||||||||||||||||||||||||
| 45 | L<DBIO::MySQL::Introspect::ForeignKeys>). None of these subs talk to the | ||||||||||||||||||||||||||||
| 46 | database or hold state; they are class methods that take scalars / hashrefs | ||||||||||||||||||||||||||||
| 47 | and return scalars / hashrefs, so they are trivially unit-testable in | ||||||||||||||||||||||||||||
| 48 | isolation. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | The reader submodules all scope their C<information_schema> rows to the | ||||||||||||||||||||||||||||
| 51 | current C<DATABASE()>, then drop any row whose table did not survive | ||||||||||||||||||||||||||||
| 52 | L<DBIO::MySQL::Introspect::Tables> (views are kept, but the C<$tables> | ||||||||||||||||||||||||||||
| 53 | hash is still the single authority for "which objects exist"). That filter | ||||||||||||||||||||||||||||
| 54 | predicate and the C<column_type> size parser were the real duplication when | ||||||||||||||||||||||||||||
| 55 | these readers lived in one file; they live here so the per-section layout | ||||||||||||||||||||||||||||
| 56 | mandated by core ADR 0018 carries no copy-paste. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 METHODS | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 keep_table | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | next unless DBIO::MySQL::Introspect::Util->keep_table($tables, $name); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | True when C<$name> is present in the C<$tables> hashref produced by | ||||||||||||||||||||||||||||
| 65 | L<DBIO::MySQL::Introspect::Tables>. This is the shared C<$tables> filter the | ||||||||||||||||||||||||||||
| 66 | per-table readers apply so they never emit columns / indexes / foreign keys | ||||||||||||||||||||||||||||
| 67 | for an object that L<DBIO::MySQL::Introspect::Tables> did not surface. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head2 column_size | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | my $size = DBIO::MySQL::Introspect::Util->column_size($column_type); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | Parse the size component out of a MySQL C<column_type> string. C<size> is the | ||||||||||||||||||||||||||||
| 74 | canonical companion to C<data_type>: L<DBIO::Introspect::Base> relies on it to | ||||||||||||||||||||||||||||
| 75 | size the columns it builds. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | varchar(100) -> 100 | ||||||||||||||||||||||||||||
| 78 | int(11) unsigned -> 11 | ||||||||||||||||||||||||||||
| 79 | decimal(10,2) -> 10 | ||||||||||||||||||||||||||||
| 80 | enum('a','b') -> undef (set/enum lengths are not portable) | ||||||||||||||||||||||||||||
| 81 | text, json, int -> undef | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | DBIO & DBIx::Class Authors | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||
| 90 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||||||||||
| 91 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 94 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||