NAME

DBIO::PostgreSQL::Introspect::Normalize - Pure normalization helpers for PostgreSQL introspected metadata

VERSION

version 0.900000

DESCRIPTION

Leaf module that holds the pure-data normalization helpers used by DBIO::PostgreSQL::Introspect to translate raw pg_catalog rows into the canonical column-info shape consumed by DBIO::Generate. None of these subs talk to the database or hold state; they are class methods that take scalars / hashrefs and return scalar / hashref results, so they are trivially unit-testable in isolation.

The helpers are:

  • "name" -- lowercase / preserve-case policy

  • "data_type" -- parses pg_catalog.format_type into a data_type/size pair, handling all the special forms (varchar(n), numeric(p,s), interval(n), pgvector, etc.)

  • "default_value" -- normalises the pg_get_expr(adbin, adrelid) string into a scalar / SCALAR-ref suitable for round-tripping through DBIO and detects the nextval(...) sequence pattern

  • "array" -- decodes the {a,b,c} form returned by DBD::Pg for array columns into a Perl ArrayRef

name

my $normalised = DBIO::PostgreSQL::Introspect::Normalize->name(
    $name, $preserve_case,
);

Returns the column / index / constraint name as a Perl string. When $preserve_case is false (the default) the name is lowercased to match DBIx::Class convention. undef stays undef.

data_type

DBIO::PostgreSQL::Introspect::Normalize->data_type(
    $info, $column, $enum_values,
);

Mutates $info in place to set data_type and (where appropriate) size from the raw pg_catalog row. Handles the size-bearing variants (varchar(n), numeric(p,s), interval(n), pgvector vector(n), etc.) and the size-stripped aliases (character varying - text). Enum columns are detected via type_category and the canonical schema.name reference is recorded under pg_enum_type / extra/custom_type_name / extra/list. Pass the already-fetched values ArrayRef in $enum_values when normalising a column that references an enum (the caller has to look it up in the model because that lookup is stateful and not the leaf module's job).

default_value

DBIO::PostgreSQL::Introspect::Normalize->default_value(
    $info, $default_expr, $is_primary_key,
);

Normalises the pg_get_expr(adbin, adrelid) string returned by the introspect query into either a Perl scalar, a SCALAR ref (for SQL expressions like now()), or nextval('schema.seq'::regclass) auto-increment metadata. Mutates $info in place.

array

my $arr = DBIO::PostgreSQL::Introspect::Normalize->array($value);

Decodes the {a,b,c} string DBD::Pg returns for text[] / integer[] columns into a Perl ArrayRef. Already-an-ArrayRef values pass through unchanged. undef returns undef.

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.