| 1 | package DBIO::Cake; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: DDL-like DSL for defining DBIO result classes | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 14 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 14 | ▶ | use DBIO::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 14 | our @EXPORT; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | our %EXPORT_TAGS; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 14 | my @col_types = qw( | |||||||||||||||||||||||||||||||||||||||||
| 17 | integer tinyint smallint bigint | ||||||||||||||||||||||||||||||||||||||||||
| 18 | serial bigserial smallserial | ||||||||||||||||||||||||||||||||||||||||||
| 19 | numeric decimal | ||||||||||||||||||||||||||||||||||||||||||
| 20 | real float4 double float8 float | ||||||||||||||||||||||||||||||||||||||||||
| 21 | char varchar | ||||||||||||||||||||||||||||||||||||||||||
| 22 | text tinytext mediumtext longtext | ||||||||||||||||||||||||||||||||||||||||||
| 23 | blob tinyblob mediumblob longblob bytea | ||||||||||||||||||||||||||||||||||||||||||
| 24 | boolean bool | ||||||||||||||||||||||||||||||||||||||||||
| 25 | date datetime timestamp time timetz timestamptz interval | ||||||||||||||||||||||||||||||||||||||||||
| 26 | enum set uuid json jsonb xml hstore | ||||||||||||||||||||||||||||||||||||||||||
| 27 | array | ||||||||||||||||||||||||||||||||||||||||||
| 28 | money | ||||||||||||||||||||||||||||||||||||||||||
| 29 | vector halfvec sparsevec bit varbit | ||||||||||||||||||||||||||||||||||||||||||
| 30 | inet cidr macaddr macaddr8 | ||||||||||||||||||||||||||||||||||||||||||
| 31 | tsvector tsquery | ||||||||||||||||||||||||||||||||||||||||||
| 32 | point line lseg box path polygon circle | ||||||||||||||||||||||||||||||||||||||||||
| 33 | int4range int8range numrange tsrange tstzrange daterange | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | my @col_modifiers = qw( | |||||||||||||||||||||||||||||||||||||||||
| 37 | null auto_inc fk default unsigned on_create on_update | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | my @table_funcs = qw( | |||||||||||||||||||||||||||||||||||||||||
| 41 | table col primary_key unique | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 14 | my @relationship_funcs = qw( | |||||||||||||||||||||||||||||||||||||||||
| 45 | belongs_to has_one has_many might_have many_to_many | ||||||||||||||||||||||||||||||||||||||||||
| 46 | rel_one rel_many | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 14 | my @cascade_funcs = qw( | |||||||||||||||||||||||||||||||||||||||||
| 50 | ddl_cascade dbic_cascade | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 14 | my @other_funcs = qw( | |||||||||||||||||||||||||||||||||||||||||
| 54 | view idx | ||||||||||||||||||||||||||||||||||||||||||
| 55 | col_created col_updated cols_updated_created | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 14 | @EXPORT = ( | |||||||||||||||||||||||||||||||||||||||||
| 59 | @col_types, @col_modifiers, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | @table_funcs, @relationship_funcs, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | @cascade_funcs, @other_funcs, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | ▶ | sub type_function_names { return @col_types } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type_function_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # Per-caller options storage | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 14 | my %CALLER_OPTS; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 53 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=21 SCAR=41.5
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 53 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 53 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | # Parse import options | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 53 | my %opts = ( | |||||||||||||||||||||||||||||||||||||||||
| 76 | autoclean => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | inflate_datetime => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | inflate_json => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | inflate_jsonb => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | retrieve_defaults => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 53 | my @components; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 53 | my $storage_class = 'DBIO::Storage::DBI'; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 53 | ▶ | while (my $arg = shift @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($arg eq '-V2') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | # default and only version, no-op | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ▶ | elsif ($arg =~ /^-(\w+)$/ && _resolve_driver_defaults($1)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$arg =~ /^-(\w+)$/ and _resolve_driver_defaults($1)
MC/DC0%0/2
$arg =~ /^-(\w+)$/ and _resolve_driver_defaults($1)
$arg =~ /^-(\w+)$/
_resolve_driver_defaults($1)
Truth table0%0/3
A and B
A= $arg =~ /^-(\w+)$/B= _resolve_driver_defaults($1)
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | # Driver shortcut: -Pg, -MySQL, -SQLite etc. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # Uses the DBIO::Storage::DBI driver registry to find the storage class, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # calls cake_defaults() on it to get driver-recommended options. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $storage_class = _resolve_driver_defaults($1); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my %driver_opts = $storage_class->cake_defaults; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | @opts{keys %driver_opts} = values %driver_opts; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | elsif ($arg eq '-inflate_datetime') { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $opts{inflate_datetime} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | elsif ($arg eq '-inflate_json') { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $opts{inflate_json} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | elsif ($arg eq '-inflate_jsonb') { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $opts{inflate_jsonb} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif ($arg eq '-retrieve_defaults') { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $opts{retrieve_defaults} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | elsif ($arg eq '-autoclean') { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $opts{autoclean} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | elsif ($arg eq '-no_autoclean') { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $opts{autoclean} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 53 | $opts{_storage_class} = $storage_class; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # Enable strict and warnings in caller | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 53 | strict->import; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 53 | warnings->import; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | # Set up inheritance -- caller ISA DBIO::Core | ||||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 14 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 53 | ▶ | unless ($caller->isa('DBIO::Core')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 47 | require DBIO::Core; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 47 | push @{"${caller}::ISA"}, 'DBIO::Core'; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # Always load Timestamp for col_created/col_updated/cols_updated_created | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 53 | push @components, 'Timestamp'; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # Collect components from the type registry based on active options | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 53 | my %seen_components; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 53 | require DBIO::Storage::DBI; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 53 | for my $type_name ($storage_class->all_type_names) { | |||||||||||||||||||||||||||||||||||||||||
| 140 | 424 | ▶ | my $info = $storage_class->type_info($type_name) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 424 | ▶ | for my $opt (@{ $info->{cake_options} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info->{'cake_options'} || []
MC/DC0%0/1
$info->{'cake_options'} || []
$info->{'cake_options'}
Truth table50%1/2
A
A= $info->{'cake_options'}
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 424 | ▶ | if ($opts{$opt}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $seen_components{$_}++ for @{ $info->{components} || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$info->{'components'} || []
MC/DC0%0/1
$info->{'components'} || []
$info->{'components'}
Truth table0%0/2
A
A= $info->{'components'}
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 53 | push @components, keys %seen_components; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 53 | $caller->load_components(@components); | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | # Store per-caller options | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 53 | $CALLER_OPTS{$caller} = \%opts; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | # Export all DSL functions into the caller | ||||||||||||||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 14 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 53 | for my $func (@EXPORT) { | |||||||||||||||||||||||||||||||||||||||||
| 159 | 4876 | *{"${caller}::${func}"} = \&{$func}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | # Schedule namespace cleanup at end of caller's scope | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 53 | ▶ | if ($opts{autoclean}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 53 | require namespace::clean; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 53 | namespace::clean->import( | |||||||||||||||||||||||||||||||||||||||||
| 167 | -cleanee => $caller, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | @EXPORT, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # --- Internal helpers --- | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub _resolve_driver_defaults { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_driver_defaults: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my ($driver_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # Look up the storage class from the DBIO::Storage::DBI driver registry | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | require DBIO::Storage::DBI; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $storage_class = DBIO::Storage::DBI->driver_storage_class($driver_name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | DBIO::Util::assert_class_name($storage_class); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | eval "require $storage_class; 1" or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return $storage_class if $storage_class->can('cake_defaults'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 365 | ▶ | sub _caller_class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_caller_class: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | # Walk up the call stack to find the result class (skip DBIO::Cake frames) | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 365 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 365 | ▶ | while (my $pkg = caller($i)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 369 | ▶ | return $pkg unless $pkg eq __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return caller(1); | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 212 | ▶ | sub _expand_col_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_col_options: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 212 | my (@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 212 | my %merged; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 212 | ▶ | while (@args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 330 | my $key = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 330 | my $val = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 330 | ▶ | if ($key =~ /^(.+?)\.(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | # Dotted notation: e.g. extra.unsigned => 1 becomes { extra => { unsigned => 1 } } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 8 | my ($outer, $inner) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | ▶ | $merged{$outer} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$merged{$outer} ||= {}
MC/DC0%0/1
$merged{$outer} ||= {}
$merged{$outer}
Truth table50%1/2
A
A= $merged{$outer}
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | $merged{$outer}{$inner} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 322 | $merged{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 212 | return %merged; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # --- Table declaration --- | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 53 | ▶ | sub table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 53 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 53 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 53 | $class->table($name); | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # --- Column declaration --- | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 212 | ▶ | sub col { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
col: called CC=25 SCAR=38.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 212 | my ($name, @options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 212 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | # Scalar refs are shorthand for default values: | ||||||||||||||||||||||||||||||||||||||||||
| 236 | # col id => uuid \'gen_random_uuid()'; | ||||||||||||||||||||||||||||||||||||||||||
| 237 | # col active => boolean \1; | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 212 | ▶ | @options = map { ref $_ eq 'SCALAR' || ref $_ eq 'REF' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_ eq "SCALAR" or ref $_ eq "REF"
MC/DC50%1/2
ref $_ eq "SCALAR" or ref $_ eq "REF"
ref $_ eq "SCALAR"
ref $_ eq "REF"
Truth table66%2/3
A or B
A= ref $_ eq "SCALAR"B= ref $_ eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | ? (default_value => $_) : $_ } @options; | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 212 | my %info = _expand_col_options(@options); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # Default: not nullable | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 212 | ▶ | $info{is_nullable} = 0 unless exists $info{is_nullable}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # If -retrieve_defaults is active and there is a default_value, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # set retrieve_on_insert | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 212 | my $opts = $CALLER_OPTS{$class}; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 212 | ▶ | if ($opts && $opts->{retrieve_defaults} && exists $info{default_value}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$opts and $opts->{"retrieve_defaults"} and exists $info{"default_value"}
$opts and $opts->{"retrieve_defaults"}
MC/DC0%0/3
$opts and $opts->{"retrieve_defaults"} and exists $info{"default_value"}
$opts
$opts->{"retrieve_defaults"}
exists $info{"default_value"}
Truth table25%1/4
A and B and C
A= $optsB= $opts->{"retrieve_defaults"}C= exists $info{"default_value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | $info{retrieve_on_insert} = 1 unless exists $info{retrieve_on_insert}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | # Apply col_attrs from the type registry for active options | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 212 | ▶ | if ($opts) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 212 | ▶ | my $dt = $info{data_type} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info{'data_type'} || ''
MC/DC0%0/1
$info{'data_type'} || ''
$info{'data_type'}
Truth table50%1/2
A
A= $info{'data_type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 212 | ▶ | my $storage_class = $opts->{_storage_class} || 'DBIO::Storage::DBI'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{'_storage_class'} || 'DBIO::Storage::DBI'
MC/DC0%0/1
$opts->{'_storage_class'} || 'DBIO::Storage::DBI'
$opts->{'_storage_class'}
Truth table50%1/2
A
A= $opts->{'_storage_class'}
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 212 | ▶ | if (my $type_info = $storage_class->type_info($dt)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 14 | ▶ | for my $opt (@{ $type_info->{cake_options} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$type_info->{'cake_options'} || []
MC/DC0%0/1
$type_info->{'cake_options'} || []
$type_info->{'cake_options'}
Truth table50%1/2
A
A= $type_info->{'cake_options'}
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 14 | ▶ | if ($opts->{$opt}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my $attrs = $type_info->{col_attrs} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$type_info->{'col_attrs'} || {}
MC/DC0%0/1
$type_info->{'col_attrs'} || {}
$type_info->{'col_attrs'}
Truth table0%0/2
A
A= $type_info->{'col_attrs'}
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | $info{$_} //= $attrs->{$_} for keys %$attrs; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$info{$_} //= $attrs->{$_}
MC/DC0%0/2
$info{$_} //= $attrs->{$_}
$info{$_}
$attrs->{$_}
Truth table0%0/3
A //= B
A= $info{$_}B= $attrs->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | # Timestamp auto-behavior: | ||||||||||||||||||||||||||||||||||||||||||
| 269 | # col created_at => timestamp; -> NOT NULL -> set_on_create | ||||||||||||||||||||||||||||||||||||||||||
| 270 | # col updated_at => timestamp on_update; -> NOT NULL + on_update -> set_on_create + set_on_update | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # col deleted_at => timestamp null; -> nullable -> no auto-set | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # col last_login => timestamp null, on_update; -> nullable + on_update -> only set_on_update | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 212 | ▶ | my $dt = $info{data_type} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info{'data_type'} || ''
MC/DC0%0/1
$info{'data_type'} || ''
$info{'data_type'}
Truth table50%1/2
A
A= $info{'data_type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 212 | ▶ | if ($dt =~ /^(?:datetime|timestamp|timestamp with(?:out)? time zone)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 10 | ▶ | if ($info{is_nullable}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | # Nullable: no set_on_create (NULL is fine for create) | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # set_on_update stays if explicitly requested | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # NOT NULL: must have a value on create | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 8 | ▶ | $info{set_on_create} = 1 unless exists $info{set_on_create}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | # If on_update was requested, set_on_create is already implied above | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | # UUID auto-behavior: retrieve_on_insert so the driver-provided default | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # (e.g. gen_random_uuid()) comes back after INSERT | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 212 | ▶ | if ($dt eq 'uuid' && !$info{is_nullable}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dt eq "uuid" and not $info{"is_nullable"}
MC/DC100%2/2
$dt eq "uuid" and not $info{"is_nullable"}
$dt eq "uuid"
not $info{"is_nullable"}
Truth table100%3/3
A and not(B)
A= $dt eq "uuid"B= not $info{"is_nullable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | ▶ | $info{retrieve_on_insert} = 1 unless exists $info{retrieve_on_insert}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 212 | $class->add_columns($name => \%info); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | # --- Column modifiers (return key-value pairs, pass through @_) --- | ||||||||||||||||||||||||||||||||||||||||||
| 295 | # The @_ passthrough enables comma-free DDL syntax: | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # col id => integer auto_inc; | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # Perl parses this as integer(auto_inc()) -- auto_inc returns its pairs, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | # which become @_ for integer, which passes them through. | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 26 | ▶ | sub null { is_nullable => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
null: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 21 | ▶ | sub auto_inc { is_auto_increment => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_inc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | sub fk { is_foreign_key => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fk: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 8 | ▶ | sub unsigned { 'extra.unsigned' => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unsigned: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | ▶ | sub on_update { set_on_update => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_update: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | sub on_create { set_on_create => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 4 | ▶ | sub default { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | return (default_value => $val, @_); | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | # --- Column type functions (return key-value pairs, pass through @_) --- | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | # Integers | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 59 | ▶ | sub integer { data_type => 'integer', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
integer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | sub tinyint { data_type => 'tinyint', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tinyint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ▶ | sub smallint { data_type => 'smallint', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
smallint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | sub bigint { data_type => 'bigint', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bigint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | # Serial (auto-increment integer shortcuts) | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 5 | ▶ | sub serial { data_type => 'serial', is_auto_increment => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serial: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | ▶ | sub bigserial { data_type => 'bigserial', is_auto_increment => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bigserial: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | ▶ | sub smallserial { data_type => 'smallserial', is_auto_increment => 1, @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
smallserial: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # Numeric | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | ▶ | sub numeric { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
numeric: called CC=8 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | ▶ | my $precision = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | my $scale = shift if defined $precision && @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $precision and @_ and &Scalar::Util::looks_like_number($_[0])
defined $precision and @_
MC/DC0%0/3
defined $precision and @_ and &Scalar::Util::looks_like_number($_[0])
defined $precision
@_
&Scalar::Util::looks_like_number($_[0])
Truth table25%1/4
A and B and C
A= defined $precisionB= @_C= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | ▶ | data_type => 'numeric', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | (defined $precision ? (size => [defined $scale ? ($precision, $scale) : $precision]) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 331 | @_; | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | sub decimal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decimal: called CC=8 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | ▶ | my $precision = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | ▶ | my $scale = shift if defined $precision && @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $precision and @_ and &Scalar::Util::looks_like_number($_[0])
defined $precision and @_
MC/DC0%0/3
defined $precision and @_ and &Scalar::Util::looks_like_number($_[0])
defined $precision
@_
&Scalar::Util::looks_like_number($_[0])
Truth table25%1/4
A and B and C
A= defined $precisionB= @_C= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | ▶ | data_type => 'decimal', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | (defined $precision ? (size => [defined $scale ? ($precision, $scale) : $precision]) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 339 | @_; | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | # Floats | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | ▶ | sub real { data_type => 'real', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
real: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | sub float4 { data_type => 'real', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
float4: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | sub double { data_type => 'double precision', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
double: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub float8 { data_type => 'double precision', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
float8: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | ▶ | sub float { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
float: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | ▶ | my $bits = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | ▶ | data_type => 'float', (defined $bits ? (size => $bits) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # Strings | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub char { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
char: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | my $size = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table0%0/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | data_type => 'char', size => ($size || 1), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 27 | ▶ | sub varchar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
varchar: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 27 | ▶ | my $size = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 27 | ▶ | data_type => 'varchar', size => ($size || 255), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | # Text | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 37 | ▶ | sub text { data_type => 'text', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | sub tinytext { data_type => 'tinytext', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tinytext: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | sub mediumtext { data_type => 'mediumtext', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mediumtext: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub longtext { data_type => 'longtext', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
longtext: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | # Binary | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | sub blob { data_type => 'blob', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blob: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | sub tinyblob { data_type => 'tinyblob', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tinyblob: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | sub mediumblob { data_type => 'mediumblob', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mediumblob: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub longblob { data_type => 'longblob', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
longblob: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | ▶ | sub bytea { data_type => 'bytea', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bytea: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | # Boolean | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 4 | ▶ | sub boolean { data_type => 'boolean', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
boolean: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | sub bool { data_type => 'boolean', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bool: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | # Date/Time | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 3 | ▶ | sub date { data_type => 'date', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | sub datetime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetime: called CC=5 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | ▶ | my $tz = shift if @_ && !ref($_[0]) && $_[0] !~ /^[a-z_]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@_ and not ref $_[0] and not $_[0] =~ /^[a-z_]+$/
@_ and not ref $_[0]
MC/DC0%0/3
@_ and not ref $_[0] and not $_[0] =~ /^[a-z_]+$/
@_
not ref $_[0]
not $_[0] =~ /^[a-z_]+$/
Truth table25%1/4
A and not(B) and not(C)
A= @_B= not ref $_[0]C= not $_[0] =~ /^[a-z_]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | data_type => 'datetime', (defined $tz ? (timezone => $tz) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 7 | ▶ | sub timestamp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timestamp: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 7 | ▶ | my $tz = shift if @_ && !ref($_[0]) && $_[0] !~ /^[a-z_]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@_ and not ref $_[0] and not $_[0] =~ /^[a-z_]+$/
@_ and not ref $_[0]
MC/DC0%0/3
@_ and not ref $_[0] and not $_[0] =~ /^[a-z_]+$/
@_
not ref $_[0]
not $_[0] =~ /^[a-z_]+$/
Truth table50%2/4
A and not(B) and not(C)
A= @_B= not ref $_[0]C= not $_[0] =~ /^[a-z_]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 7 | ▶ | data_type => 'timestamp', (defined $tz ? (timezone => $tz) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub time { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | my $tz = shift if @_ && !ref($_[0]) && $_[0] !~ /^[a-z_]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@_ and not ref $_[0] and not $_[0] =~ /^[a-z_]+$/
@_ and not ref $_[0]
MC/DC0%0/3
@_ and not ref $_[0] and not $_[0] =~ /^[a-z_]+$/
@_
not ref $_[0]
not $_[0] =~ /^[a-z_]+$/
Truth table0%0/4
A and not(B) and not(C)
A= @_B= not ref $_[0]C= not $_[0] =~ /^[a-z_]+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | data_type => 'time', (defined $tz ? (timezone => $tz) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | sub timetz { data_type => 'time with time zone', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timetz: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | ▶ | sub timestamptz { data_type => 'timestamp with time zone', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timestamptz: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | ▶ | sub interval { data_type => 'interval', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interval: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | # Enum/Set -- all args are the allowed values (modifiers go outside via col) | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | ▶ | sub enum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | data_type => 'enum', extra => { list => [@_] }; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | data_type => 'set', extra => { list => [@_] }; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | # UUID | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 4 | ▶ | sub uuid { data_type => 'uuid', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uuid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | # JSON | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | ▶ | sub json { data_type => 'json', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 2 | ▶ | sub jsonb { data_type => 'jsonb', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
jsonb: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | # XML / hstore | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | ▶ | sub xml { data_type => 'xml', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 2 | ▶ | sub hstore { data_type => 'hstore', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hstore: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | # Array (PostgreSQL) | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | sub array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
array: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | my $type_info = shift; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 2 | ▶ | if (ref $type_info eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | return (data_type => 'ARRAY', %$type_info, @_); | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | # If called as array(text) where text() returns (data_type => 'text', ...), | ||||||||||||||||||||||||||||||||||||||||||
| 429 | # extract the actual type name from the key-value pairs | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 2 | ▶ | if ($type_info eq 'data_type' && @_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type_info eq "data_type" and @_
MC/DC50%1/2
$type_info eq "data_type" and @_
$type_info eq "data_type"
@_
Truth table66%2/3
A and B
A= $type_info eq "data_type"B= @_
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | my $actual_type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | return (data_type => $actual_type . '[]', @_); | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 1 | return (data_type => $type_info . '[]', @_); | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | # Money | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | ▶ | sub money { data_type => 'money', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
money: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | # Vector / AI (pgvector) | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 3 | ▶ | sub vector { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vector: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 3 | ▶ | my $dims = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 3 | ▶ | data_type => 'vector', (defined $dims ? (size => $dims) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 2 | ▶ | sub halfvec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
halfvec: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 2 | ▶ | my $dims = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 2 | ▶ | data_type => 'halfvec', (defined $dims ? (size => $dims) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | ▶ | sub sparsevec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sparsevec: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | ▶ | my $dims = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | ▶ | data_type => 'sparsevec', (defined $dims ? (size => $dims) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | # Bit strings | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 2 | ▶ | sub bit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bit: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 2 | ▶ | my $size = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 2 | ▶ | data_type => 'bit', (defined $size ? (size => $size) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 2 | ▶ | sub varbit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
varbit: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | ▶ | my $size = shift if @_ && Scalar::Util::looks_like_number($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and &Scalar::Util::looks_like_number($_[0])
MC/DC0%0/2
@_ and &Scalar::Util::looks_like_number($_[0])
@_
&Scalar::Util::looks_like_number($_[0])
Truth table33%1/3
A and B
A= @_B= &Scalar::Util::looks_like_number($_[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | ▶ | data_type => 'varbit', (defined $size ? (size => $size) : ()), @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | # Network types (PostgreSQL) | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 3 | ▶ | sub inet { data_type => 'inet', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | ▶ | sub cidr { data_type => 'cidr', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cidr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 2 | ▶ | sub macaddr { data_type => 'macaddr', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
macaddr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | ▶ | sub macaddr8 { data_type => 'macaddr8', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
macaddr8: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | # Full-text search (PostgreSQL) | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 3 | ▶ | sub tsvector { data_type => 'tsvector', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tsvector: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | ▶ | sub tsquery { data_type => 'tsquery', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tsquery: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | # Geometric types (PostgreSQL) | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 2 | ▶ | sub point { data_type => 'point', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
point: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | ▶ | sub line { data_type => 'line', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | ▶ | sub lseg { data_type => 'lseg', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lseg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | ▶ | sub box { data_type => 'box', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
box: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | sub path { data_type => 'path', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | ▶ | sub polygon { data_type => 'polygon', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
polygon: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | ▶ | sub circle { data_type => 'circle', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
circle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | # Range types (PostgreSQL) | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 3 | ▶ | sub int4range { data_type => 'int4range', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
int4range: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | ▶ | sub int8range { data_type => 'int8range', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
int8range: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | ▶ | sub numrange { data_type => 'numrange', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
numrange: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | ▶ | sub tsrange { data_type => 'tsrange', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tsrange: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | ▶ | sub tstzrange { data_type => 'tstzrange', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tstzrange: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | ▶ | sub daterange { data_type => 'daterange', @_ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
daterange: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | # --- Keys / Constraints --- | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 48 | ▶ | sub primary_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
primary_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 48 | my (@cols) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 48 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 499 | 48 | $class->set_primary_key(@cols); | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 3 | ▶ | sub unique { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unique: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 3 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 3 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 3 | ▶ | if (@args == 1 && ref $args[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
@args == 1 and ref $args[0] eq "ARRAY"
MC/DC50%1/2
@args == 1 and ref $args[0] eq "ARRAY"
@args == 1
ref $args[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | # unique \@cols -- anonymous unique constraint | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | $class->add_unique_constraint($args[0]); | |||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | ▶ | elsif (@args == 2 && !ref $args[0] && ref $args[1] eq 'ARRAY') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
@args == 2 and not ref $args[0] and ref $args[1] eq "ARRAY"
@args == 2 and not ref $args[0]
MC/DC0%0/3
@args == 2 and not ref $args[0] and ref $args[1] eq "ARRAY"
@args == 2
not ref $args[0]
ref $args[1] eq "ARRAY"
Truth table25%1/4
A and not(B) and C
A= @args == 2B= not ref $args[0]C= ref $args[1] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | # unique $name => \@cols | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 2 | $class->add_unique_constraint($args[0] => $args[1]); | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # Pass through | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $class->add_unique_constraint(@args); | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | # --- Relationships --- | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 7 | ▶ | sub belongs_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
belongs_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 7 | my ($name, $related, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 7 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 7 | $class->belongs_to($name, $related, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | sub has_one { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_one: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my ($name, $related, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $class->has_one($name, $related, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | ▶ | sub has_many { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_many: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | my ($name, $related, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | $class->has_many($name, $related, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | sub might_have { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
might_have: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | my ($name, $related, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | $class->might_have($name, $related, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | sub many_to_many { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
many_to_many: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my ($name, $link, $foreign, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $class->many_to_many($name, $link, $foreign, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | # rel_one: belongs_to with LEFT JOIN (nullable FK convenience) | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | sub rel_one { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rel_one: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my ($name, $related, $cond, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | my %attrs; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | %attrs = %{pop @rest} if @rest && ref $rest[-1] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@rest and ref $rest[-1] eq "HASH"
MC/DC0%0/2
@rest and ref $rest[-1] eq "HASH"
@rest
ref $rest[-1] eq "HASH"
Truth table0%0/3
A and B
A= @restB= ref $rest[-1] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $attrs{join_type} = 'left'; | |||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | $class->belongs_to($name, $related, $cond, \%attrs); | |||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | # rel_many: has_many (already LEFT JOIN by default, but explicit) | ||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | sub rel_many { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rel_many: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | my ($name, $related, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $class->has_many($name, $related, @rest); | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | # --- Cascade helpers --- | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | sub ddl_cascade { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ddl_cascade: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | on_delete => 'CASCADE', | |||||||||||||||||||||||||||||||||||||||||
| 574 | on_update => 'CASCADE', | ||||||||||||||||||||||||||||||||||||||||||
| 575 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | sub dbic_cascade { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbic_cascade: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | cascade_delete => 1, | |||||||||||||||||||||||||||||||||||||||||
| 581 | cascade_copy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 582 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | # --- Views --- | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | sub view { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my ($name, $sql, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | $class->table_class('DBIO::ResultSource::View') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | unless $class->table_class->isa('DBIO::ResultSource::View'); | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | require DBIO::ResultSource::View; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $class->table($name); | |||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $class->result_source_instance->view_definition($sql); | |||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if ($opts{depends_on}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | $class->result_source_instance->deploy_depends_on( | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | ref $opts{depends_on} ? $opts{depends_on} : [$opts{depends_on}] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | # --- Indexes --- | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | # What a driver block of idx may hold, per driver. The driver names are | ||||||||||||||||||||||||||||||||||||||||||
| 608 | # DBIO::ResultSource->index_declaration_drivers; this is the keys of each. | ||||||||||||||||||||||||||||||||||||||||||
| 609 | 14 | my %IDX_DRIVER_KEYS = ( | |||||||||||||||||||||||||||||||||||||||||
| 610 | pg => [qw(where using with expression)], | ||||||||||||||||||||||||||||||||||||||||||
| 611 | sqlite => [qw(where expression)], | ||||||||||||||||||||||||||||||||||||||||||
| 612 | mysql => [qw(using)], | ||||||||||||||||||||||||||||||||||||||||||
| 613 | oracle => [qw(expression)], | ||||||||||||||||||||||||||||||||||||||||||
| 614 | mssql => [qw(kind)], | ||||||||||||||||||||||||||||||||||||||||||
| 615 | firebird => [], | ||||||||||||||||||||||||||||||||||||||||||
| 616 | sybase => [], | ||||||||||||||||||||||||||||||||||||||||||
| 617 | informix => [], | ||||||||||||||||||||||||||||||||||||||||||
| 618 | duckdb => [qw(expression)], | ||||||||||||||||||||||||||||||||||||||||||
| 619 | clickhouse => [qw(type granularity expression)], | ||||||||||||||||||||||||||||||||||||||||||
| 620 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 68 | ▶ | sub _idx_driver_names { DBIO::ResultSource->index_declaration_drivers } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_idx_driver_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | # Refuses an option idx would store and never read, so a misplaced | ||||||||||||||||||||||||||||||||||||||||||
| 625 | # `using => 'gin'` or `unique => 1` cannot silently yield a plain index. | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 41 | ▶ | sub _check_idx_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_idx_keys: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | 41 | my ($name, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 628 | 41 | ▶ | my $list = sub { join ', ', map "'$_'", @_ }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | 41 | my @drivers = _idx_driver_names(); | |||||||||||||||||||||||||||||||||||||||||
| 630 | 41 | my @top = (qw(type options), @drivers); | |||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 41 | for my $key (sort keys %$options) { | |||||||||||||||||||||||||||||||||||||||||
| 633 | 48 | ▶ | next if grep { $_ eq $key } @top; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | my ($home) = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 8 | ▶ | my $d = $_; grep { $_ eq $key } @{ $IDX_DRIVER_KEYS{$d} || [] } | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$IDX_DRIVER_KEYS{$d} || []
MC/DC100%1/1
$IDX_DRIVER_KEYS{$d} || []
$IDX_DRIVER_KEYS{$d}
Truth table100%2/2
A
A= $IDX_DRIVER_KEYS{$d}
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | } @drivers; | ||||||||||||||||||||||||||||||||||||||||||
| 637 | 8 | ▶ | my $hint = defined $home | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | ? "; put '$key' inside $home => { ... }" | ||||||||||||||||||||||||||||||||||||||||||
| 639 | : $key eq 'unique' | ||||||||||||||||||||||||||||||||||||||||||
| 640 | ? "; use type => 'unique'" | ||||||||||||||||||||||||||||||||||||||||||
| 641 | : ''; | ||||||||||||||||||||||||||||||||||||||||||
| 642 | 8 | Carp::croak("idx: index '$name': unknown key '$key' (valid keys: " | |||||||||||||||||||||||||||||||||||||||||
| 643 | . $list->(@top) . ")$hint"); | ||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 33 | for my $drv (@drivers) { | |||||||||||||||||||||||||||||||||||||||||
| 647 | 309 | ▶ | next unless exists $options->{$drv}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | Carp::croak("idx: index '$name': $drv must be a hashref, $drv => { ... }") | ||||||||||||||||||||||||||||||||||||||||||
| 649 | 28 | ▶ | unless ref $options->{$drv} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | 25 | ▶ | my @valid = @{ $IDX_DRIVER_KEYS{$drv} || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$IDX_DRIVER_KEYS{$drv} || []
MC/DC0%0/1
$IDX_DRIVER_KEYS{$drv} || []
$IDX_DRIVER_KEYS{$drv}
Truth table50%1/2
A
A= $IDX_DRIVER_KEYS{$drv}
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 25 | for my $key (sort keys %{ $options->{$drv} }) { | |||||||||||||||||||||||||||||||||||||||||
| 652 | 29 | ▶ | next if grep { $_ eq $key } @valid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 3 | Carp::croak("idx: index '$name': unknown key '$key' in $drv => { ... } " | |||||||||||||||||||||||||||||||||||||||||
| 654 | . "(valid keys: " . $list->(@valid) . ")"); | ||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | 41 | ▶ | sub idx { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
idx: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 660 | 41 | my ($name, $fields, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 661 | 41 | my $class = _caller_class(); | |||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 41 | _check_idx_keys($name, \%options); | |||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 22 | my %driver = map { $_ => $options{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 666 | 27 | grep { exists $options{$_} } _idx_driver_names(); | |||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | 27 | my $source = $class->result_source_instance; | |||||||||||||||||||||||||||||||||||||||||
| 669 | $source->add_index_declaration({ | ||||||||||||||||||||||||||||||||||||||||||
| 670 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 671 | columns => $fields, | ||||||||||||||||||||||||||||||||||||||||||
| 672 | type => $options{type}, | ||||||||||||||||||||||||||||||||||||||||||
| 673 | options => $options{options}, | ||||||||||||||||||||||||||||||||||||||||||
| 674 | 27 | ▶ | (%driver ? (driver => \%driver) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | # --- Timestamp column helpers --- | ||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | ▶ | sub col_created { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
col_created: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 1 | ▶ | my $name = shift || 'created_at'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'created_at'
MC/DC0%0/1
shift() || 'created_at'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 682 | 1 | col($name, timestamp, @_); | |||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 1 | ▶ | sub col_updated { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
col_updated: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | ▶ | my $name = shift || 'updated_at'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'updated_at'
MC/DC0%0/1
shift() || 'updated_at'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | col($name, timestamp, on_update, @_); | |||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 1 | ▶ | sub cols_updated_created { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cols_updated_created: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | col_created(@_); | |||||||||||||||||||||||||||||||||||||||||
| 692 | 1 | col_updated(@_); | |||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | __END__ | ||||||||||||||||||||||||||||||||||||||||||