|
NAMEDBIx::Class::VirtualColumns - Add virtual columns to DBIx::Class schemataSYNOPSISpackage Your::Schema::Class; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components( "VirtualColumns", "PK", "Core", ); __PACKAGE__->table("sometable"); __PACKAGE__->add_columns(qw/dbcol1 dbcol2/); __PACKAGE__->add_virtual_columns(qw/vcol1 vcol2 vcol3/); # ========================================================= # Somewhere else my $item = $schema->resultset('Artist')->find($id); $item->vcol1('test'); # Set 'test' $item->get_column('vcol1'); # Return 'test' my $otheritem = $schema->resultset('Artist')->create({ dbcol1 => 'value1', dbcol2 => 'value2', vcol1 => 'value3', vcol2 => 'value4', }); $otheritem->vcol1(); # Now is 'value3' # Get the column metadata just like for a regular DBIC column my $info = $result_source->column_info('vcol1'); DESCRIPTIONThis 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. USAGEUse this module if you want to add 'virtual' columns to a DBIC class which behave like real columns (e.g. if you want to use the "set_column", "get_column" methods)However if you only want to add non-column data to DBIx::Class::Row objects, then there are easier/better ways: __PACKAGE__->mk_group_accessors(simple => qw(foo bar baz)); METHODSadd_virtual_columnsAdds 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:
add_virtual_columnShortcut for add_virtual_columnshas_any_columnReturns true if the source has a virtual or regular column of this name, false otherwise.has_virtual_columnReturns 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_columnShortcut for remove_virtual_columns_virtual_filterSplits attributes for regular and virtual columnsnewOverloaded method. "new" in DBIx::Class::Rowget_columnOverloaded method. "get_colum" in DBIx::Class::Rowget_columnsOverloaded method. "get_colums" in DBIx::Class::Rowstore_columnOverloaded method. "store_column" in DBIx::Class::Rowset_columnOverloaded method. "set_column" in DBIx::Class::Rowcolumn_infoOverloaded method. "column_info" in DBIx::Class::ResultSourceAdditionally returns the HASH key 'virtual' which indicates if the requested column is virtual or not. updateOverloaded method. "update" in DBIx::Class::RowCAVEATSThe best way to add non-column data to DBIC objects is to use Class::Accessor::Grouped.__PACKAGE__->mk_group_accessors(simple => qw(foo bar baz)); Use DBIx::Class::VirtualColumns only if you rely on DBIx::Class::Row methods like "set_column", "get_column", ... SUPPORTThis module was just a proof of concept, and is not actively developed anymore. Patches are still welcome though.Please report any bugs to "bug-dbix-class-virtualcolumns@rt.cpan.org", or through the web interface at <http://rt.cpan.org/Public/Bug/Report.html?Queue=DBIx::Class::VirtualColumns>. I will be notified, and then you'll automatically be notified of progress on your report as I make changes. AUTHORMaroš Kollár CPAN ID: MAROS maros [at] k-1.com L<http://www.revdev.at> ACKNOWLEDGEMENTSThis 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/>).COPYRIGHTDBIx::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.
Visit the GSP FreeBSD Man Page Interface. |