NAME

DBIx::QuickORM::Schema::Autofill - Autofill configuration for schema introspection.

DESCRIPTION

Holds the type maps, affinity callbacks, and hooks used while autofilling a schema from a live database. It maps introspected SQL types to DBIx::QuickORM::Type classes, runs user-supplied hooks at well-known points, and generates field and link accessors on autovivified row classes.

SYNOPSIS

my $autofill = DBIx::QuickORM::Schema::Autofill->new(
    types      => {...},
    affinities => {...},
    hooks      => {...},
);

$autofill->define_autorow($row_class, $table);

ATTRIBUTES

types

Hashref mapping SQL type names to type objects/classes.

affinities

Hashref mapping affinity names to arrayrefs of callbacks.

hooks

Hashref mapping hook names to arrayrefs of callbacks.

autorow

The autovivified row class configuration.

skip

Nested hashref describing what to skip during autofill.

PUBLIC METHODS

$bool = $autofill->is_valid_hook($name)

True if $name is a recognized hook name.

$out = $autofill->hook($name, \%args, $seed)

Run every callback registered for the named hook as a pipeline. Each hook has a designated seed key in \%args (for example table for the table hooks, name for the accessor hooks). Every callback is called with the args (plus autofill) with the running value under the seed key, and its return value becomes the running value passed to the next callback and ultimately returned. A callback that modifies the seed in place must still return it so the callbacks after it (and the caller) see the same value. The pipeline starts from $seed when given, otherwise from the seed key's value in \%args; with a single registered callback this matches the old single-callback behavior exactly.

$val = $autofill->skip(@path)

Walk the nested skip hashref along @path, returning the value found or false (0) as soon as any step is missing.

$autofill->process_column(\%col)

Resolve the column's scalar-ref type into a real type object, using the type map first and then affinity callbacks. Updates the column's type and affinity in place when a match is found.

$autofill->define_autorow($row_class, $table)

Load (or autovivify) the row class, then install field accessors for each column and link accessors for each link, honoring the field_accessor and link_accessor hooks.

An accessor that already exists on the row class is left untouched. Each generated accessor name must be unique on the row class; if two relationships, or a relationship and a column, resolve to the same name this croaks and names the conflict. Names are resolved after any aliases and link_accessor/link hooks, so those hooks resolve a collision: give the relationships distinct aliases, or a name hook that returns a distinct name for each.

Return a human-readable description of a link for collision diagnostics: the table it points to, the local columns it joins on, and where the link was defined.

$msg = $autofill->_autorow_collision_error($row_class, $accessor, $claimed_by, $link)

Build the croak message for an accessor-name collision: name the row class and accessor, describe both sides of the collision, and tell the user how to resolve it.

SOURCE

The source code repository for DBIx::QuickORM can be found at https://github.com/exodist/DBIx-QuickORM.

MAINTAINERS

Chad Granum <exodist7@gmail.com>

AUTHORS

Chad Granum <exodist7@gmail.com>

COPYRIGHT

Copyright Chad Granum <exodist7@gmail.com>.

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

See https://dev.perl.org/licenses/