The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

DBIx::Class::LookupColumn::Auto - A dbic component for detecting lookup tables within a schema and adding accessors to all DBIx::Class::ResultSource classes.

VERSION

Version 0.01

SYNOPSIS

__PACKAGE__->load_components( qw/+DBIx::Class::LookupColumn::Auto/ );

my @tables = __PACKAGE__-> sources;

__PACKAGE__->add_lookups( targets => [ grep { ! /Type$/ } @tables ], lookups => [ grep { /Type$/ } @tables ],

        options => {
                relation_name_builder => sub{
                        my ( $class, %args) = @_;
                        
                        $args{lookup} =~ /^(.+)Type$/;
                        lc( $1 );
                },
                lookup_field_name => sub{
                        'name'; 
                }
        }
);

DESCRIPTION

This module generates a few convenient methods (accessors) for a whole schema's client tables. It makes use of DBIx::Class:LookupColumn.

What is meant as lookup table is a table containing some terms definition, such as PermissionType (permission_id, name) with such data (1, 'Administrator'; 2, 'User'; 3, 'Reader') associated with a client table (also called target table) such as User, whose metas might look like this : (id, first_name, last_name, permission_id).

It is also possible to add accessors in a non-automated way by doing a copy/paste of the code diplayed when verbose is true (See add_lookups).

EXPORT

add_lookups

METHODS

add_lookups

Arguments: \@target_tables, \@lookup_tables, \%options?
Returned value: no return value.
Description: create the methods (accessors) to all client classes whose name is passed as argument.
Example: User->find( {last_name => 'uchiwa'} )->permission.

_target2lookups

Description: Build a nested hashing. For internal use.

_guess_relation_name

Description: Find out by default the appropriate relation name for building the accessors. For internal use.

_guess_field_name

Description: Find out by default the appropriate column in the lookup table. For internal use.

AUTHOR

Karl Forner <karl.forner@gmail.com>

BUGS

Please report any bugs or feature requests to bug-dbix-class-lookupcolumn-auto at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-LookupColumn-Auto. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc DBIx::Class::LookupColumn::Auto

You can also look for information at:

LICENCE AND COPYRIGHT

Copyright 2012 Karl Forner, All Rights Reserved.

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