| 1 | package DBIO::PostgreSQL::Introspect::Normalize; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Pure normalization helpers for PostgreSQL introspected metadata | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 172 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 172 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 172 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 172 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 76 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 76 | my ($class, $name, $preserve_case) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 76 | ▶ | return undef unless defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 74 | ▶ | return $preserve_case ? $name : lc $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 60 | ▶ | sub data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data_type: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 60 | my ($class, $info, $column, $enum_values) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 60 | ▶ | if ($column->{type_category} && $column->{type_category} eq 'e' && $column->{enum_type}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$column->{"type_category"} and $column->{"type_category"} eq "e" and $column->{"enum_type"}
$column->{"type_category"} and $column->{"type_category"} eq "e"
MC/DC66%2/3
$column->{"type_category"} and $column->{"type_category"} eq "e" and $column->{"enum_type"}
$column->{"type_category"}
$column->{"type_category"} eq "e"
$column->{"enum_type"}
Truth table75%3/4
A and B and C
A= $column->{"type_category"}B= $column->{"type_category"} eq "e"C= $column->{"enum_type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | my $qualified = $column->{type_schema} && $column->{type_schema} ne 'public' | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ? "$column->{type_schema}.$column->{enum_type}" | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | : $column->{enum_type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$column->{"type_schema"} and $column->{"type_schema"} ne "public"
MC/DC50%1/2
$column->{"type_schema"} and $column->{"type_schema"} ne "public"
$column->{"type_schema"}
$column->{"type_schema"} ne "public"
Truth table66%2/3
A and B
A= $column->{"type_schema"}B= $column->{"type_schema"} ne "public"
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | $info->{data_type} = 'enum'; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | $info->{extra}{list} = $class->array($enum_values) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | if $enum_values; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | $info->{extra}{custom_type_name} = $qualified; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | $info->{pg_enum_type} = $qualified; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 56 | ▶ | my $type = lc($column->{data_type} || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$column->{'data_type'} || ''
MC/DC0%0/1
$column->{'data_type'} || ''
$column->{'data_type'}
Truth table50%1/2
A
A= $column->{'data_type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # Dispatch table: each entry is [pattern, callback]. The callback | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # mutates $info and returns 1 to claim the match, 0 to fall through. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | my @DISPATCH = ( | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ▶ | [qr/^(?:character varying|varchar)\((\d+)\)\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | $info->{data_type} = 'varchar'; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 5 | $info->{size} = 0 + $1; | |||||||||||||||||||||||||||||||||||||||||
| 44 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | [qr/^character varying\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $info->{data_type} = 'text'; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | $info->{original}{data_type} = 'varchar'; | |||||||||||||||||||||||||||||||||||||||||
| 48 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | [qr/^(?:character|char)\((\d+)\)\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | $info->{data_type} = 'char'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | $info->{size} = 0 + $1; | |||||||||||||||||||||||||||||||||||||||||
| 52 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | [qr/^(numeric|decimal)\((\d+),(\d+)\)\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | $info->{data_type} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | $info->{size} = [ 0 + $2, 0 + $3 ]; | |||||||||||||||||||||||||||||||||||||||||
| 56 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | [qr/^(?:bit varying|varbit)\((\d+)\)\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | $info->{data_type} = 'varbit'; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | $info->{size} = 0 + $1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | [qr/^bit\((\d+)\)\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | $info->{data_type} = 'bit'; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | $info->{size} = 0 + $1; | |||||||||||||||||||||||||||||||||||||||||
| 64 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # A model read under an empty search_path has the schema in front of | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # the type: public.vector(3). | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | ▶ | [qr/^(?:(?:"[^"]+"|\w+)\.)?(vector|halfvec|sparsevec)\((\d+)\)\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | $info->{data_type} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | $info->{size} = 0 + $2; | |||||||||||||||||||||||||||||||||||||||||
| 70 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | [qr/^(timestamp|time)\((\d+)\) without time zone\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | $info->{data_type} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | $info->{size} = 0 + $2; | |||||||||||||||||||||||||||||||||||||||||
| 74 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | [qr/^timestamp without time zone\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | $info->{data_type} = 'timestamp'; | |||||||||||||||||||||||||||||||||||||||||
| 77 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | [qr/^time without time zone\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | $info->{data_type} = 'time'; | |||||||||||||||||||||||||||||||||||||||||
| 80 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # format_type writes the precision behind the first word: | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # "timestamp(3) with time zone", never "timestamp with time zone(3)". | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | ▶ | [qr/^(timestamp|time)\((\d+)\) with time zone\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | $info->{data_type} = "$1 with time zone"; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | $info->{size} = 0 + $2; | |||||||||||||||||||||||||||||||||||||||||
| 86 | }], | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | [qr/^interval\((\d+)\)\z/, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | $info->{data_type} = 'interval'; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | $info->{size} = 0 + $1; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 56 | }], | |||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 56 | for my $entry (@DISPATCH) { | |||||||||||||||||||||||||||||||||||||||||
| 94 | 479 | my ($re, $cb) = @$entry; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 479 | ▶ | if ($type =~ $re) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 35 | $cb->(); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 35 | return; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | # Fallback aliases (when no size-bearing match wins). | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 21 | $type =~ s/^character$/char/; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 21 | $type =~ s/^character varying$/varchar/; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 21 | $type =~ s/^bit varying$/varbit/; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 21 | $info->{data_type} = $type; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 28 | ▶ | sub default_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_value: called CC=17 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 28 | my ($class, $info, $default, $is_primary_key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 28 | ▶ | return unless defined $default; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 18 | my $value = $default; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 18 | $value =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 18 | $value =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 18 | ▶ | if ($value =~ /\bnextval\('([^']+)'::(?:text|regclass)\)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | $info->{is_auto_increment} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | $info->{sequence} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | ▶ | $info->{retrieve_on_insert} = 1 if $is_primary_key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 14 | ▶ | if ($value =~ /^["'](.*?)['"](?:::[\w\s\."]+)?\z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 6 | $info->{default_value} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | elsif ($value =~ /^\((-?\d.*?)\)(?:::[\w\s\."]+)?\z/) { | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | $info->{default_value} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | elsif ($value =~ /^(-?\d.*?)(?:::[\w\s\."]+)?\z/) { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | $info->{default_value} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | elsif ($value =~ /^NULL:?/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | my $null = 'null'; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | $info->{default_value} = \$null; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | my $literal = lc($value) eq 'now()' ? 'current_timestamp' : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $literal =~ s/\bCURRENT_TIMESTAMP\b/lc $&/ge; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | $info->{default_value} = \$literal; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 14 | ▶ | if (!$info->{is_auto_increment} && $is_primary_key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $info->{"is_auto_increment"} and $is_primary_key
MC/DC50%1/2
not $info->{"is_auto_increment"} and $is_primary_key
not $info->{"is_auto_increment"}
$is_primary_key
Truth table66%2/3
not(A) and B
A= not $info->{"is_auto_increment"}B= $is_primary_key
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | $info->{retrieve_on_insert} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 14 | ▶ | my $type = $info->{data_type} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$info->{'data_type'} || ''
MC/DC100%1/1
$info->{'data_type'} || ''
$info->{'data_type'}
Truth table100%2/2
A
A= $info->{'data_type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 14 | ▶ | if ($type =~ /^bool/i && exists $info->{default_value} && !ref $info->{default_value}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$type =~ /^bool/i and exists $info->{"default_value"} and not ref $info->{"default_value"}
$type =~ /^bool/i and exists $info->{"default_value"}
MC/DC66%2/3
$type =~ /^bool/i and exists $info->{"default_value"} and not ref $info->{"default_value"}
$type =~ /^bool/i
exists $info->{"default_value"}
not ref $info->{"default_value"}
Truth table75%3/4
A and B and not(C)
A= $type =~ /^bool/iB= exists $info->{"default_value"}C= not ref $info->{"default_value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | if ($info->{default_value} eq '0') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | my $false = 'false'; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | $info->{default_value} = \$false; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | elsif ($info->{default_value} eq '1') { | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | my $true = 'true'; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $info->{default_value} = \$true; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 13 | ▶ | sub array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
array: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 13 | my ($class, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 13 | ▶ | return undef if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 12 | ▶ | return $value if ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 9 | my $raw = $value; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 9 | $raw =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | ▶ | Carp::croak('not a PostgreSQL array literal') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | unless $raw =~ /\A\{(.*)\}\z/s; | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 8 | my $body = $1; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 8 | ▶ | return [] if $body =~ /\A\s*\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | my @items; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | pos($body) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 177 | 19 | $body =~ /\G\s*/gc; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 19 | ▶ | if ($body =~ /\G"((?:[^"\\]|\\.)*)"\s*/gcs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 8 | (my $item = $1) =~ s/\\(.)/$1/gs; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 8 | push @items, $item; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | elsif ($body =~ /\G((?:[^,"\\{}]|\\.)*)/gcs) { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 11 | my $item = $1; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 11 | $item =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 11 | my $was_null = $item =~ /\Anull\z/i; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 11 | $item =~ s/\\(.)/$1/gs; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 11 | ▶ | push @items, $was_null ? undef : $item; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 19 | ▶ | if ($body =~ /\G,/gc) { next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 6 | ▶ | last if (pos($body) // 0) == length $body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
pos $body // 0
MC/DC0%0/1
pos $body // 0
pos $body
Truth table50%1/2
A
A= pos $body
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | Carp::croak('not a PostgreSQL array literal'); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 6 | return \@items; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 172 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | __END__ | ||||||||||||||||||||||||||||||||||||||||||