DBIx::Class::LookupColumn::Auto - A dbic component for installing LookupColumn relations on a whole schema at once.
package MySchema; __PACKAGE__->load_components( qw/LookupColumn::Auto/ ); my @tables = __PACKAGE__->sources; # get all table names my @candidates = grep { ! /Type$/ } @tables; # tables that do NOT end with Type my @lookups = grep { /Type$/ } @tables; # tables that DO end with Type == the Lookup Tables ! __PACKAGE__->add_lookups( targets => \@candidates, lookups => \@lookups, # function that will generate the relation names: here we build it from the Lookup Table relation_name_builder => sub{ my ( $class, %args) = @_; $args{lookup} =~ /^(.+)Type$/; # remove the end (Type) from the Lookup table name lc( $1 ); }, # function that gives the name of the column that holds the definitions/values: here it is always 'name' lookup_field_name_builder => sub { 'name' } );
This component automates the addition of the Lookup (see "Lookup Tables" in DBIx::Class::LookupColumn) relations to a whole set of tables.
Given a set of potential target tables (the tables on which to add the Lookup relations), and a set of Lookup tables, the component will select all the belongs_to relations defined in the target tables pointing to a Lookup table present in the set and add a Lookup relation automatically.
It is also possible to add accessors manuall by doing a copy/paste of the code diplayed with the verbose option (See add_lookups).
__PACKAGE__->add_lookups( { targets => [], lookups => [], relation_name_builder? => sub {}, lookup_field_name_builder? => sub {}, verbose? => boolean } )
This will iterate through the set of targets tables on all belongs_to relations pointing to a table included in lookups and add a corresponding relation.
Arguments (hash keys) :
An ArrayRef of the names of the tables on which to detect and install the Lookup relations.
An ArrayRef of the names of the Lookup tables.
Optional. FuncRef for building the accessors base name. By default the name of the Lookup table in small caps. Arguments (hash keys) : { target => ?, lookup => ?, foreign_key => ? }.
Optional. FuncRef for specifying the concerned column name in the Lookup table. By default the first varchar type column in the Lookup table.
Optional. Boolean for displaying the code for adding a Lookup relation. Copy/paste it the right place of your code. By default set to false, then non-verbose.
Karl Forner <karl.forner@gmail.com>
Thomas Rubattel <rubattel@cpan.org>
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.
bug-dbix-class-lookupcolumn-auto at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc DBIx::Class::LookupColumn::Auto
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-LookupColumn-Auto
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/DBIx-Class-LookupColumn-Auto
CPAN Ratings
http://cpanratings.perl.org/d/DBIx-Class-LookupColumn-Auto
Search CPAN
http://search.cpan.org/dist/DBIx-Class-LookupColumn-Auto/
Copyright 2012 Karl Forner and Thomas Rubattel, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the terms as Perl itself.
To install DBIx::Class::LookupColumn, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::LookupColumn
CPAN shell
perl -MCPAN -e shell install DBIx::Class::LookupColumn
For more information on module installation, please visit the detailed CPAN module installation guide.