| 1 | package DBIO::PostgreSQL::Introspect::Parse; | ||||||||||
| 2 | # ABSTRACT: Pure parsers for raw PostgreSQL metadata strings | ||||||||||
| 3 | |||||||||||
| 4 | 16 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 16 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | sub include_columns { | ||||||||
|
Subroutine
include_columns: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 10 | 4 | my ($class, $definition) = @_; | |||||||||
| 11 | 4 | ▶ | return [] unless defined $definition; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 3 | ▶ | if ($definition =~ /\bINCLUDE\s*\(([^)]+)\)/i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 2 | my $cols = $1; | |||||||||
| 14 | 2 | return [ map { s/^\s+|\s+$//g; s/^"|"$//g; $_ } split /,/, $cols ]; | |||||||||
| 15 | } | ||||||||||
| 16 | 1 | return []; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | 5 | ▶ | sub storage_params { | ||||||||
|
Subroutine
storage_params: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||
| 21 | 5 | my ($class, $reloptions) = @_; | |||||||||
| 22 | 5 | ▶ | return {} unless defined $reloptions; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 4 | my $raw = $reloptions; | |||||||||
| 24 | 4 | ▶ | $raw =~ s/^\{|\}$//g if !ref $raw; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 4 | ▶ | my @items = ref $raw ? @$raw : split /,/, $raw; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 4 | my %params; | |||||||||
| 27 | 4 | for my $item (@items) { | |||||||||
| 28 | 5 | $item =~ s/^\s+|\s+$//g; | |||||||||
| 29 | 5 | ▶ | if ($item =~ /^(.+?)=(.+)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 5 | $params{$1} = $2; | |||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | 4 | return \%params; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 16 | 1; | |||||||||
| 37 | |||||||||||
| 38 | __END__ | ||||||||||
| 39 | |||||||||||
| 40 | =pod | ||||||||||
| 41 | |||||||||||
| 42 | =encoding UTF-8 | ||||||||||
| 43 | |||||||||||
| 44 | =head1 NAME | ||||||||||
| 45 | |||||||||||
| 46 | DBIO::PostgreSQL::Introspect::Parse - Pure parsers for raw PostgreSQL metadata strings | ||||||||||
| 47 | |||||||||||
| 48 | =head1 VERSION | ||||||||||
| 49 | |||||||||||
| 50 | version 0.900001 | ||||||||||
| 51 | |||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||
| 53 | |||||||||||
| 54 | Leaf module with pure-data parsers that turn raw C<pg_catalog> strings | ||||||||||
| 55 | (typically produced by C<pg_get_indexdef> and C<reloptions>) into the | ||||||||||
| 56 | canonical Perl structures consumed by L<DBIO::Generate>. None of these | ||||||||||
| 57 | subs talk to the database or hold state; they are class methods that | ||||||||||
| 58 | take scalars / arrayrefs and return arrayrefs / hashrefs. | ||||||||||
| 59 | |||||||||||
| 60 | The parsers are: | ||||||||||
| 61 | |||||||||||
| 62 | =over 4 | ||||||||||
| 63 | |||||||||||
| 64 | =item * L</include_columns> -- extracts the C<INCLUDE (col1, col2, ...)> | ||||||||||
| 65 | clause from an index definition | ||||||||||
| 66 | |||||||||||
| 67 | =item * L</storage_params> -- decodes a C<reloptions> array / string of | ||||||||||
| 68 | C<key=value> pairs into a hashref | ||||||||||
| 69 | |||||||||||
| 70 | =back | ||||||||||
| 71 | |||||||||||
| 72 | =head2 include_columns | ||||||||||
| 73 | |||||||||||
| 74 | my $cols = DBIO::PostgreSQL::Introspect::Parse->include_columns($def); | ||||||||||
| 75 | |||||||||||
| 76 | Returns an ArrayRef of column names listed in the C<INCLUDE (col, col)> | ||||||||||
| 77 | clause of the index definition C<$def>. Returns C<[]> when the clause | ||||||||||
| 78 | is missing or the definition is C<undef>. Column names are stripped of | ||||||||||
| 79 | surrounding whitespace and double quotes. | ||||||||||
| 80 | |||||||||||
| 81 | =head2 storage_params | ||||||||||
| 82 | |||||||||||
| 83 | my $params = DBIO::PostgreSQL::Introspect::Parse->storage_params($reloptions); | ||||||||||
| 84 | |||||||||||
| 85 | Decodes C<reloptions> (C<pg_class.reloptions>) into a hashref. Accepts | ||||||||||
| 86 | either a string of the form C<{key=value, key=value}> or an ArrayRef | ||||||||||
| 87 | of C<key=value> strings. Returns C<{}> for empty / undef input. | ||||||||||
| 88 | |||||||||||
| 89 | =head1 AUTHOR | ||||||||||
| 90 | |||||||||||
| 91 | DBIO & DBIx::Class Authors | ||||||||||
| 92 | |||||||||||
| 93 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 94 | |||||||||||
| 95 | Copyright (C) 2026 DBIO Authors | ||||||||||
| 96 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||
| 97 | Based on DBIx::Class, heavily modified. | ||||||||||
| 98 | |||||||||||
| 99 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 100 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||