NAME
DBIx::Class::VirtualColumns - Add virtual columns to DBIx::Class schemata
SYNOPSIS
package Your::Schema::Class;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(
"VirtualColumns",
"PK",
"Core",
);
__PACKAGE__->table("sometable");
__PACKAGE__->add_columns('dbcol1','dbcol2', ...);
__PACKAGE__->add_virtual_columns(w/vcol1 vcol2 vcol3/);
# Somewhere else
my $item = $schema->resultset('Artist')->find($id);
$item->vcol1('test'); #
$item->get_column('vcol1'); # Return 'test'
my $otheritem = $schema->resultset('Artist')->create({
dbcol1 => 'value',
dbcol2 => 'value',
vcol1 => 'value',
vcol2 => 'value',
});
DESCRIPTION
This module allows to specify 'virtual columns' in DBIx::Class schema classes. Virtual columns behave almost like regular columns but are not stored in the database. They may be used to store temporary information in the DBIx::Class::Row object and without introducting an additional interface.
Most DBIx::Class methods like set_column
, set_columns
, get_column
, get_columns
, column_info
, ... will work with regular as well as virtual columns.
METHODS
add_virtual_columns
Adds virtual columns to the result source. If supplied key => hashref pairs, uses the hashref as the column_info for that column. Repeated calls of this method will add more columns, not replace them.
$table->add_virtual_columns(qw/column1 column2/);
OR
$table->add_virtual_columns(column1 => \%column1_info, column2 => \%column2_info, ...);
The column names given will be created as accessor methods on your DBIx::Class::Row objects
, you can change the name of the accessor by supplying an "accessor" in the column_info hash.
The following options are currently recognised/used by DBIx::Class::VirtualColumns:
accessor
Use this to set the name of the accessor method for this column. If unset, the name of the column will be used.
add_virtual_column
Shortcut for add_virtual_columns
has_any_column
Returns true if the source has a virtual or regular column of this name, false otherwise.
has_virtual_column
Returns true if the source has a virtual column of this name, false otherwise.
remove_virtual_columns
$table->remove_columns(qw/col1 col2 col3/);
Removes virtual columns from the result source.
remove_virtual_column
Shortcut for remove_virtual_column
_virtual_filter
Splits attributes for base and virtual columns
new
Overloaded method. DBIx::Class::Row#new
get_column
Overloaded method. DBIx::Class::Row#get_colum
get_columns
Overloaded method. DBIx::Class::Row#get_colums
store_column
Overloaded method. DBIx::Class::Row#store_column
set_column
Overloaded method. DBIx::Class::Row#set_column
column_info
Overloaded method. DBIx::Class::ResultSource#column_info
Additionally returns the HASH key 'virtual' which indicates if the requested column is virtual or not.
update
Overloaded method. DBIx::Class::Row#update
SUPPORT
Please report any bugs or feature requests to bug-dbix-class-virtualcolumns@rt.cpan.org
, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
AUTHOR
Maroš Kollár
CPAN ID: MAROS
maros [at] k-1.com
L<http://www.revdev.at>
ACKNOWLEDGEMENTS
This module was written for Revdev http://www.revdev.at, a nice litte software company I run with Koki and Domm (http://search.cpan.org/~domm/).
COPYRIGHT
DBIx::Class::VirtualColumns is Copyright (c) 2008 Maroš Kollár - http://www.revdev.at
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 357:
Non-ASCII character seen before =encoding in 'Maroš'. Assuming UTF-8