DDL/Util.pm

filter: Statementstmt 89.8% 160 / 178 Branchbran 72.5% 45 / 62 Conditioncond 46.0% 23 / 50 MC/DCmcdc 20.0% 6 / 30 Subroutinesub 82.9% 34 / 41 Podpod 100% 4 / 4 totaltotal 74.5% 272 / 365 CC 53 SCAR 21.1
CC
53
Cov
79%
init
22.9
_exporter_expand_sub
15.7
sqlt_entity_map
12.0
CRAP 8.3
« DDL/Table.pm ↑ Summary DDL.pm »
1 package CXC::DB::DDL::Util;
2  
3 # ABSTRACT: CXC::DB::DDL utilities
4  
5 8 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use experimental 'signatures', 'postderef', 'declared_refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 our $VERSION = '0.21';
11  
12 8 ▶use List::Util qw( pairs first );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Sub::Util qw( set_subname );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use Ref::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use Hash::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 8 ▶use DBI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶use DBI::Const::GetInfoType;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 8 ▶use CXC::DB::DDL::Constants -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 8 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 8 ▶use base 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 8 ▶use constant BASE_TYPE_PACKAGE => __PACKAGE__ . '::Type';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 8 ▶use constant DEFAULT_FIELD_CLASS => 'CXC::DB::DDL::Field';
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 8 our %EXPORT_TAGS = (
35 schema_funcs => [qw( xFIELDS xCHECK xTYPE )],
36 misc => [ 'SQL_TYPE_NAMES', 'SQL_TYPE_VALUES', 'sqlt_entity_map', 'db_version' ],
37 );
38  
39 8 ▶our @EXPORT_OK = ( map { Ref::Util::is_arrayref( $_ ) ? $_->@* : () } values %EXPORT_TAGS );
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_arrayref($_) ? : 16 0 16
40  
41 my sub gen_package_name;
42 my sub types;
43  
44 0 ▶my sub croak {
Subroutine croak: not called CC=1 SCAR=6.9
45 0 require Carp;
46 0 goto \&Carp::croak;
47 }
48  
49  
50 8 my %CACHE = (
51 'DBI' => {
52 tag => ':sql_types',
53 types => {
54 package => gen_package_name( 'DBI' ),
55 },
56 subs => {},
57 fields => {
58 default => +( DEFAULT_FIELD_CLASS ),
59 },
60 },
61 );
62  
63 0 ▶my sub is_supported_dbd ( $dbd ) {
Subroutine is_supported_dbd: not called CC=1 SCAR=6.9
64 0 my %supported;
65 0 @supported{ 'DBI', SUPPORTED_DBDS, keys %CACHE } = ();
66 0 return exists $supported{$dbd};
67 }
68  
69 9 ▶sub gen_package_name ( $dbd, @xtra ) {
Subroutine gen_package_name: called CC=2 SCAR=9.2
70 # create a unique class for this blend
71 9 ▶ return join q{::}, BASE_TYPE_PACKAGE, Digest::MD5::md5_hex( $dbd // (), @xtra );
Condition33%1/3
$dbd // ()
l!l&&r!l&&!r
900
MC/DC0%0/2
$dbd // ()
$dbd ()
Truth table33%1/3
A // B
A= $dbdB= ()
ABresult
1X1
011
000
72 }
73  
74 26 ▶my sub init ( $globals ) {
Subroutine init: called CC=15 SCAR=31.3
75  
76 # we can reach this sub through multiple paths; only init once.
77 26 ▶ return if exists $globals->{ __PACKAGE__() };
Branch: 1 branch
BranchTrueFalseTotal
if exists $globals->{"CXC::DB::DDL::Util"} 10 16 26
78  
79 # request to add support for specified DBD?
80 16 ▶ if ( my $request = $globals->{add_dbd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $request = $globals->{"add_dbd"}) 1 15 16
81 1 ▶ Ref::Util::is_hashref( $request )
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_hashref($request) or croak "add_dbd: expected the DBD entry to be a hashref, got @{[ref $request];} " 1 0 1
82 0 or croak( "add_dbd: expected the DBD entry to be a hashref, got @{[ ref $request ]} " );
83 my ( $dbd, $tag, $field_class, $type_class )
84 1 = $request->@{ 'dbd', 'tag', 'field_class', 'type_class' };
85  
86 defined( $dbd ) && defined( $tag ) && defined( $field_class )
87 or croak(
88 sprintf( 'add_dbd: missing dbd (%s), tag(%s), or field_class(%s)',
89 0 ▶ map { $_ // 'undef' } ( $dbd, $tag, $field_class ), ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $dbd and defined $tag and defined $field_class or croak sprintf("add_dbd: missing dbd (%s), tag(%s), or field_class(%s)", map({$_ // "undef";} $dbd, $tag, $field_class)) 1 0 1
Condition25%2/8
defined $dbd and defined $tag and defined $field_class
!ll&&!rl&&r
001
defined $dbd and defined $tag
!ll&&!rl&&r
001
$_ // "undef"
l!l
00
MC/DC0%0/3
defined $dbd and defined $tag and defined $field_class
defined $dbd defined $tag defined $field_class
MC/DC0%0/1
$_ // "undef"
$_
Truth table25%1/4
A and B and C
A= defined $dbdB= defined $tagC= defined $field_class
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/2
A
A= $_
Aresult
11
00
90  
91 # silently ignores attempts to redefine. should it warn?
92 1 ▶ if ( !exists $CACHE{$dbd} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $CACHE{$dbd}) 1 0 1
93 1 $CACHE{$dbd} = {
94 tag => $tag,
95 fields => {
96 default => $field_class,
97 },
98 types => {
99 class => $type_class,
100 package => gen_package_name( $dbd ),
101 },
102 subs => {},
103 };
104 }
105  
106 # load the dbd types by default.
107 1 ▶ $globals->{dbd} //= $dbd;
Condition33%1/3
$globals->{"dbd"} //= $dbd
l!l&&r!l&&!r
010
MC/DC0%0/2
$globals->{"dbd"} //= $dbd
$globals->{"dbd"} $dbd
Truth table33%1/3
A //= B
A= $globals->{"dbd"}B= $dbd
ABresult
1X1
011
000
108 }
109  
110 16 my %stash;
111  
112 # request particular dbd or fallback to generic DBI support
113 16 ▶ my $dbd = $globals->{dbd} // 'DBI';
Condition100%2/2
$globals->{"dbd"} // "DBI"
l!l
412
MC/DC100%1/1
$globals->{"dbd"} // "DBI"
$globals->{"dbd"}
Truth table100%2/2
A
A= $globals->{"dbd"}
Aresult
11
00
114 16 ▶ Ref::Util::is_ref( $dbd )
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_ref($dbd) and croak "dbd: value must be a scalar" 0 16 16
115 and croak( 'dbd: value must be a scalar' );
116  
117 16 ▶ defined( my $cache = $CACHE{$dbd} )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $cache = $CACHE{$dbd}) or croak "dbd: unsupported DBD: $dbd" 16 0 16
118 or croak( "dbd: unsupported DBD: $dbd" );
119  
120 16 $stash{dbd} = $dbd;
121 16 $stash{cache} = $cache;
122  
123 # Field wrappers generated by mk_field
124 # override field_class?
125 16 ▶ $stash{field_class} = $globals->{field_class} // $cache->{fields}{default};
Condition33%1/3
$globals->{"field_class"} // $cache->{"fields"}{"default"}
l!l&&r!l&&!r
0160
MC/DC0%0/2
$globals->{"field_class"} // $cache->{"fields"}{"default"}
$globals->{"field_class"} $cache->{"fields"}{"default"}
Truth table33%1/3
A // B
A= $globals->{"field_class"}B= $cache->{"fields"}{"default"}
ABresult
1X1
011
000
126 16 ▶ $stash{fields} = $cache->{fields}{ $stash{field_class} } //= {};
Condition100%2/2
$cache->{"fields"}{$stash{"field_class"}} //= {}
l!l
88
MC/DC100%1/1
$cache->{"fields"}{$stash{"field_class"}} //= {}
$cache->{"fields"}{$stash{"field_class"}}
Truth table100%2/2
A
A= $cache->{"fields"}{$stash{"field_class"}}
Aresult
11
00
127  
128 16 $globals->{ __PACKAGE__() } = \%stash;
129  
130 16 return;
131 }
132  
133 # load the types for DBI and requested DBD's into individual
134 # packages and create a merged hash of names and subs
135 # cached by a hash of the DBD names.
136  
137 571 ▶sub types ( $dbd, $collection = 'all' ) {
Subroutine types: called CC=9 SCAR=22.0
138  
139 571 ▶ defined( my $cache = $CACHE{$dbd} )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $cache = $CACHE{$dbd}) or croak "types: unsupported dbd: $dbd" 571 0 571
140 or croak( "types: unsupported dbd: $dbd" );
141  
142 571 ▶ return $cache->{types}{$collection} if defined $cache->{types}{$collection};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache->{"types"}{$collection} 563 8 571
143  
144 8 my %symbol;
145  
146 8 my $stash = Package::Stash->new( $cache->{types}{package} );
147 8 ▶ my $module = Module::Runtime::use_module( $dbd eq 'DBI' ? $dbd : "DBD::$dbd" );
Branch: 1 branch
BranchTrueFalseTotal
$dbd eq 'DBI' ? : 7 1 8
148 8 $module->import::into( $stash->name, $cache->{tag} );
149 8 my $lsymbol = $stash->get_all_symbols( 'CODE' );
150 8 my @from_keys = keys $lsymbol->%*;
151  
152 # strip off SQL_ from DBI types
153 my @to_keys
154 = $dbd eq 'DBI'
155 8 ▶ ? map { s/^SQL_//r } @from_keys
Branch: 1 branch
BranchTrueFalseTotal
$dbd eq 'DBI' ? : 7 1 8
156 : @from_keys;
157  
158 # if this is a DBD specific set of types, and an object is
159 # requested, make one. This prevents collisions when the DBD
160 # type code is the same as a standard SQL_TYPE_xxxx code.
161 # The class MUST alread be loaded, so we don't have to
162 # worry about where it is defined (inner package, etc.)
163 8 ▶ if ( my $type_class = $cache->{types}{class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type_class = $cache->{'types'}{'class'}) { } 1 7 8
164 1 my %to_key;
165 1 @to_key{@from_keys} = @to_keys;
166  
167 1 for my $from ( @from_keys ) {
168 2 my $to = $to_key{$from};
169 2 my $value = $lsymbol->{$from}->();
170 2 ▶ $symbol{$to} = set_subname "DBD_TYPE_$to", sub { $type_class->new( $from, $value ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
171 }
172 }
173  
174 else {
175 7 @symbol{@to_keys} = $lsymbol->@{@from_keys};
176 }
177  
178 # DBD specific symbols
179 8 Hash::Util::lock_hashref( $cache->{types}{dbd} = {%symbol} );
180  
181 # add DBI's symbols.
182 8 ▶ if ( $dbd ne 'DBI' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbd ne "DBI") 1 7 8
183 1 my $dbi = types( 'DBI' );
184 1 my @types = keys $dbi->%*;
185 1 @symbol{@types} = $dbi->@{@types};
186 }
187  
188 8 Hash::Util::lock_hash( %symbol );
189 8 $cache->{types}{all} = \%symbol;
190 8 return $cache->{types}{$collection};
191 }
192  
193  
194 # ensure that $field_class has been required prior to calling this.
195 122 ▶my sub _mk_field ( $name, $type, $attr, $field_class ) {
Subroutine _mk_field: called CC=1 SCAR=0.0
196  
197 # do this here and use require to prevent import loop from
198 # anything which uses CXC::DB::DDL::Field, which uses this module
199  
200 122 ▶ set_subname "${name}::_mk_field", sub ( $field ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
201 122 $field_class->new( {
202 name => $field,
203 data_type => $type,
204 is_nullable => 0,
205 $attr->%*,
206 } );
207 122 };
208  
209 }
210  
211  
212 526 ▶sub _expand_field_sub ( $, $cache, $field_class, $name, $type ) { ## no critic( Subroutines::ProhibitManyArgs )
Subroutine _expand_field_sub: called CC=5 SCAR=16.6
213  
214 526 ▶ my $symbols = ( ( $cache->{fields} //= {} )->{$field_class} //= {} )->{symbols} //= {};
Condition66%4/6
+(+($cache->{"fields"} //= {})->{$field_class} //= {})->{"symbols"} //= {}
l!l
5197
+($cache->{"fields"} //= {})->{$field_class} //= {}
l!l
5260
$cache->{"fields"} //= {}
l!l
5260
MC/DC100%1/1
+(+($cache->{"fields"} //= {})->{$field_class} //= {})->{"symbols"} //= {}
+(+($cache->{"fields"} //= {})->{$field_class} //= {})->{"symbols"}
MC/DC0%0/1
+($cache->{"fields"} //= {})->{$field_class} //= {}
+($cache->{"fields"} //= {})->{$field_class}
MC/DC0%0/1
$cache->{"fields"} //= {}
$cache->{"fields"}
Truth table100%2/2
A
A= +(+($cache->{"fields"} //= {})->{$field_class} //= {})->{"symbols"}
Aresult
11
00
Truth table50%1/2
A
A= +($cache->{"fields"} //= {})->{$field_class}
Aresult
11
00
Truth table50%1/2
A
A= $cache->{"fields"}
Aresult
11
00
215  
216 return "&$name", $symbols->{$name}
217 526 ▶ if exists $symbols->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $symbols->{$name} 118 408 526
218  
219 408 Module::Runtime::use_module( $field_class );
220  
221 0 ▶ return "&$name", $symbols->{$name} = set_subname $name, sub ( %attr ) {
Subroutine __ANON__: not called CC=1 SCAR=1.2
Subroutine UNKNOWN_TYPE: called CC=1 SCAR=1.2
222 0 _mk_field( $name, $type, \%attr, $field_class );
223 408 };
224 }
225  
226 9 ▶sub _expand_type_class_sub ( $class, $name, $cache, $dbd, $collection = 'all' ) {
Subroutine _expand_type_class_sub: called CC=6 SCAR=19.3
227  
228 9 ▶ if ( $name =~ qr/TYPE_NAMES$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ qr/TYPE_NAMES$/u) 4 5 9
229 4 ▶ return "&$name", $cache->{subs}{$name} //= set_subname $name, do {
Condition33%1/3
$cache->{"subs"}{$name} //= set_subname($name, do { my(@names) = sort(keys %{types $dbd, $collection}); sub { @names; } })
l!l&&r!l&&!r
040
MC/DC0%0/2
$cache->{"subs"}{$name} //= set_subname($name, do { my(@names) = sort(keys %{types $dbd, $collection}); sub { @names; } })
$cache->{"subs"}{$name} set_subname($name, do { my(@names) = sort(keys %{types $dbd, $collection}); sub { @names; } })
Truth table33%1/3
A //= B
A= $cache->{"subs"}{$name}B= set_subname($name, do { my(@names) = sort(keys %{types $dbd, $collection}); sub { @names; } })
ABresult
1X1
011
000
230 4 my @names = sort keys types( $dbd, $collection )->%*;
231 0 ▶ sub { @names };
Subroutine __ANON__: not called CC=1 SCAR=1.2
232 };
233 }
234  
235 # just the standard SQL ones from DBI
236 5 ▶ if ( $name =~ qr/TYPE_VALUES$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ qr/TYPE_VALUES$/u) 5 0 5
237 5 ▶ return "&$name", $cache->{subs}{$name} //= set_subname $name, do {
Condition33%1/3
$cache->{"subs"}{$name} //= set_subname($name, do { my $types = types($dbd, $collection); my(@values) = map({$types->{$_}->();} sort(keys %$types)); sub { @values; } })
l!l&&r!l&&!r
050
MC/DC0%0/2
$cache->{"subs"}{$name} //= set_subname($name, do { my $types = types($dbd, $collection); my(@values) = map({$types->{$_}->();} sort(keys %$types)); sub { @values; } })
$cache->{"subs"}{$name} set_subname($name, do { my $types = types($dbd, $collection); my(@values) = map({$types->{$_}->();} sort(keys %$types)); sub { @values; } })
Truth table33%1/3
A //= B
A= $cache->{"subs"}{$name}B= set_subname($name, do { my $types = types($dbd, $collection); my(@values) = map({$types->{$_}->();} sort(keys %$types)); sub { @values; } })
ABresult
1X1
011
000
238 5 my $types = types( $dbd, $collection );
239 5 my @values = map { $types->{$_}->() } sort keys $types->%*;
240 5 ▶ sub { @values };
Subroutine __ANON__: called CC=1 SCAR=0.0
241 };
242 }
243  
244 0 croak( "internal error: unexpected type sub name: $name" );
245 }
246  
247 16 ▶sub _exporter_validate_opts ( $class, $globals ) {
Subroutine _exporter_validate_opts: called CC=1 SCAR=0.0
248 16 init( $globals );
249 }
250  
251 10 ▶sub _exporter_expand_tag ( $class, $name, $value, $globals ) {
Subroutine _exporter_expand_tag: called CC=5 SCAR=16.3
252  
253 # _exporter_expand_tag is called before _exporter_validate_opts,
254 # so init just in case
255 10 init( $globals );
256 10 my $stash = $globals->{ __PACKAGE__() };
257 10 my $dbd = $stash->{dbd};
258  
259 # mindless copy from Exporter::Tiny::_exporter_expand_tag
260 10 ▶ return ( $class->_exporter_merge_opts( $value, $globals, @EXPORT_OK, keys types( $dbd )->%*, ) )
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "all" 4 6 10
261 if $name eq 'all';
262  
263 6 ▶ return ( $class->_exporter_merge_opts( $value, $globals, keys types( $dbd )->%*, ) )
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "type_funcs" 5 1 6
264 if $name eq 'type_funcs';
265  
266 1 ▶ if ( $name eq 'types' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "types") 1 0 1
267 # first the standard ones
268 1 my @symbols = map { 'SQL_' . $_ } keys types( 'DBI' )->%*;
269  
270 # and then the DBD specific ones
271 1 ▶ push @symbols, map { 'DBD_TYPE_' . $_ } keys types( $dbd, 'dbd' )->%*
Branch: 1 branch
BranchTrueFalseTotal
if $dbd ne "DBI" 1 0 1
272 if $dbd ne 'DBI';
273  
274 1 return ( $class->_exporter_merge_opts( $value, $globals, @symbols ) );
275 }
276  
277 0 $class->SUPER::_exporter_expand_tag( $name, $value, $globals );
278 }
279  
280 625 ▶sub _exporter_expand_sub ( $class, $name, $value, $globals, $permitted ) {
Subroutine _exporter_expand_sub: called CC=14 SCAR=27.5
281  
282 625 my $stash = $globals->{ __PACKAGE__() };
283 625 my $cache = $stash->{cache};
284 625 my $dbd = $stash->{dbd};
285  
286 # just the standard SQL ones from DBI
287 625 ▶ return $class->_expand_type_class_sub( $name, $cache, 'DBI', 'dbd' )
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "SQL_TYPE_NAMES" or $name eq "SQL_TYPE_VALUES" 9 616 625
Condition100%3/3
$name eq "SQL_TYPE_NAMES" or $name eq "SQL_TYPE_VALUES"
l!l&&r!l&&!r
45616
MC/DC100%2/2
$name eq "SQL_TYPE_NAMES" or $name eq "SQL_TYPE_VALUES"
$name eq "SQL_TYPE_NAMES" $name eq "SQL_TYPE_VALUES"
Truth table100%3/3
A or B
A= $name eq "SQL_TYPE_NAMES"B= $name eq "SQL_TYPE_VALUES"
ABresult
1X1
011
000
288 if $name eq 'SQL_TYPE_NAMES' or $name eq 'SQL_TYPE_VALUES';
289  
290 # Just those from the DBD
291 616 ▶ return $class->_expand_type_class_sub( $name, $cache, $dbd, 'dbd' )
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "DBD_TYPE_NAMES" or $name eq "DBD_TYPE_VALUES" 0 616 616
Condition33%1/3
$name eq "DBD_TYPE_NAMES" or $name eq "DBD_TYPE_VALUES"
l!l&&r!l&&!r
00616
MC/DC0%0/2
$name eq "DBD_TYPE_NAMES" or $name eq "DBD_TYPE_VALUES"
$name eq "DBD_TYPE_NAMES" $name eq "DBD_TYPE_VALUES"
Truth table33%1/3
A or B
A= $name eq "DBD_TYPE_NAMES"B= $name eq "DBD_TYPE_VALUES"
ABresult
1X1
011
000
292 if $name eq 'DBD_TYPE_NAMES' or $name eq 'DBD_TYPE_VALUES';
293  
294 # All of 'em from DBI & from the DBD
295 616 ▶ return $class->_expand_type_class_sub( $name, $cache, $dbd, 'all' )
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "TYPE_NAMES" or $name eq "TYPE_VALUES" 0 616 616
Condition33%1/3
$name eq "TYPE_NAMES" or $name eq "TYPE_VALUES"
l!l&&r!l&&!r
00616
MC/DC0%0/2
$name eq "TYPE_NAMES" or $name eq "TYPE_VALUES"
$name eq "TYPE_NAMES" $name eq "TYPE_VALUES"
Truth table33%1/3
A or B
A= $name eq "TYPE_NAMES"B= $name eq "TYPE_VALUES"
ABresult
1X1
011
000
296 if $name eq 'TYPE_NAMES' or $name eq 'TYPE_VALUES';
297  
298 616 ▶ if ( $name eq 'xTYPE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "xTYPE") 6 610 616
299 # field class may be specific to this use of Util, rather than dbd specific,
300 6 my $field_class = Module::Runtime::use_module( $stash->{field_class} );
301 60 ▶ return "&$name", $cache->{subs}{$name}{$field_class} //= set_subname $name, sub ( $type, %attr ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
302 60 _mk_field( $name, $type, \%attr, $field_class );
303 6 ▶ };
Condition33%1/3
$cache->{"subs"}{$name}{$field_class} //= set_subname($name, sub ($type, %attr) { _mk_field $name, $type, \%attr, $field_class; } )
l!l&&r!l&&!r
060
MC/DC0%0/2
$cache->{"subs"}{$name}{$field_class} //= set_subname($name, sub ($type, %attr) { _mk_field $name, $type, \%attr, $field_class; } )
$cache->{"subs"}{$name}{$field_class} set_subname($name, sub ($type, %attr) { _mk_field $name, $type, \%attr, $field_class; } )
Truth table33%1/3
A //= B
A= $cache->{"subs"}{$name}{$field_class}B= set_subname($name, sub ($type, %attr) { _mk_field $name, $type, \%attr, $field_class; } )
ABresult
1X1
011
000
304 }
305  
306 610 ▶ if ( $name =~ /^(?<pfx>DBD_TYPE|SQL)_(?<type>.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(?<pfx>DBD_TYPE|SQL)_(?<type>.*)/u) 60 550 610
307 60 ▶ $dbd = 'DBI' if $+{pfx} eq 'SQL';
Branch: 1 branch
BranchTrueFalseTotal
if $+{"pfx"} eq "SQL" 58 2 60
308 60 my \%types = $CACHE{$dbd}{types}{dbd};
309 return "&$name", $types{ $+{type} }
310 60 ▶ if exists $types{ $+{type} };
Branch: 1 branch
BranchTrueFalseTotal
if exists $types{$+{"type"}} 60 0 60
311 }
312  
313 # $symbols is a locked hash, so can't just grab a value
314 550 my $symbols = types( $dbd );
315 550 ▶ if ( exists $symbols->{$name} && defined( my $sub = $symbols->{$name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $symbols->{$name} and defined(my $sub = $symbols->{$name})) 526 24 550
Condition66%2/3
exists $symbols->{$name} and defined(my $sub = $symbols->{$name})
!ll&&!rl&&r
240526
MC/DC50%1/2
exists $symbols->{$name} and defined(my $sub = $symbols->{$name})
exists $symbols->{$name} defined(my $sub = $symbols->{$name})
Truth table66%2/3
A and B
A= exists $symbols->{$name}B= defined(my $sub = $symbols->{$name})
ABresult
0X0
100
111
316 526 return $class->_expand_field_sub( $cache, $stash->{field_class}, $name, $sub->() );
317 }
318  
319  
320 24 $class->SUPER::_exporter_expand_sub( $name, $value, $globals, $permitted );
321 }
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408  
409  
410  
411  
412  
413  
414  
415  
416  
417  
418  
419  
420  
421  
422  
423  
424  
425  
426  
427  
428  
429  
430  
431  
432  
433  
434  
435  
436  
437  
438  
439  
440  
441  
442  
443  
444 1 ▶sub xFIELDS ( @fields ) {
Subroutine xFIELDS: called CC=1 SCAR=0.0
Pod documented
445 1 return fields => [ map { $_->value->( $_->key ) } pairs( @fields ) ];
446 }
447  
448  
449  
450  
451  
452  
453  
454  
455  
456  
457  
458  
459  
460  
461  
462  
463  
464  
465  
466  
467  
468  
469  
470  
471 0 ▶sub xCHECK ( $field, @values ) {
Subroutine xCHECK: not called CC=1 SCAR=6.9
Pod documented
472 0 ( check => sprintf( "$field in ( %s )", join( ', ', map { qq("$_") } @values ) ), )
473 }
474  
475  
476  
477  
478  
479  
480  
481  
482  
483  
484  
485  
486  
487  
488  
489  
490  
491  
492  
493  
494  
495  
496  
497  
498  
499  
500 0 ▶sub sqlt_entity_map ( $dbd, $entity ) {
Subroutine sqlt_entity_map: not called CC=3 SCAR=24.8
Pod documented
501 0 state $map = {
502 +( DBD_POSTGRESQL ) => {
503 producer => 'PostgreSQL',
504 db_version => 'postgres_version',
505 },
506 +( DBD_SYBASE ) => {
507 producer => 'Sybase',
508 db_version => undef,
509 },
510 +( DBD_SQLITE ) => {
511 producer => 'SQLite',
512 db_version => 'sqlite_version',
513 },
514  
515 };
516  
517 0 ▶ my $entity_map = $map->{$dbd} // return undef;
Condition0%0/2
$map->{$dbd} // (return undef)
l!l
00
MC/DC0%0/1
$map->{$dbd} // (return undef)
$map->{$dbd}
Truth table0%0/2
A
A= $map->{$dbd}
Aresult
11
00
518 return exists $entity_map->{$entity}
519 0 ▶ ? $entity_map->{$entity}
Branch: 1 branch
BranchTrueFalseTotal
exists $entity_map->{$entity} ? : 0 0 0
520 : croak( "unkown entity: $entity" );
521 }
522  
523  
524  
525  
526  
527  
528  
529  
530  
531  
532 0 ▶sub db_version( $dbh ) {
Subroutine db_version: not called CC=2 SCAR=17.9
Pod documented
533  
534 0 my $dbd = $dbh->{Driver}->{Name};
535  
536 return $dbd eq DBD_POSTGRESQL
537 ? $dbh->{pg_server_version}
538 0 ▶ : $dbh->get_info( $GetInfoType{SQL_DBMS_VER} );
Branch: 1 branch
BranchTrueFalseTotal
$dbd eq 'Pg' ? : 0 0 0
539 }
540  
541 8 1;
542  
543 #
544 # This file is part of CXC-DB-DDL
545 #
546 # This software is Copyright (c) 2022 by Smithsonian Astrophysical Observatory.
547 #
548 # This is free software, licensed under:
549 #
550 # The GNU General Public License, Version 3, June 2007
551 #
552  
553 __END__
« DDL/Table.pm ↑ Summary DDL.pm »