Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

dbix::class::dynamicdefault(3pm) [debian man page]

DBIx::Class::DynamicDefault(3pm)			User Contributed Perl Documentation			  DBIx::Class::DynamicDefault(3pm)

NAME
DBIx::Class::DynamicDefault - Automatically set and update fields SYNOPSIS
package My::Schema::SomeTable; __PACKAGE__->load_components(qw/DynamicDefault ... Core/); __PACKAGE__->add_columns( quux => { data_type => 'integer' }, quux_plus_one => { data_type => 'integer', dynamic_default_on_create => &quux_plus_one_default, dynamic_default_on_update => 'quux_plus_one_default', }, last_changed => { data_type => 'integer', dynamic_default_on_create => 'now', dynamic_default_on_update => 'now, }, ); sub quux_plus_one_default { my ($self) = @_; return $self->quux + 1; } sub now { return DateTime->now->epoch; } Now, any update or create actions will set the specified columns to the value returned by the callback you specified as a method name or code reference. DESCRIPTION
Automatically set and update fields with values calculated at runtime. OPTIONS
dynamic_default_on_create dynamic_default_on_create => sub { ... } dynamic_default_on_create => 'method_name' When inserting a new row all columns with the "dynamic_default_on_create" option will be set to the return value of the specified callback unless the columns value has been explicitly set. The callback, that'll be invoked with the row object as its only argument, may be a code reference or a method name. dynamic_default_on_update dynamic_default_on_update => sub { ... } dynamic_default_on_update => 'method_name' When updating a row all columns with the "dynamic_default_on_update" option will be set to the return value of the specified callback unless the columns value has been explicitly set. Columns will only be altered if other dirty columns exist. See "always_update" on how to change this. always_update always_update => 1 When setting "always_update" to 1 "dynamic_default_on_update" callbacks will always be invoked, even if no other columns are dirty. AUTHOR
Florian Ragwitz <rafl@debian.org> LICENSE
This software is copyright (c) 2008 by Florian Ragwitz. This is free software; you can redistribute it and/or modify it under the same terms as perl itself. perl v5.14.2 2012-04-14 DBIx::Class::DynamicDefault(3pm)

Check Out this Related Man Page

DBIx::Class::Schema::KiokuDB(3pm)			User Contributed Perl Documentation			 DBIx::Class::Schema::KiokuDB(3pm)

NAME
DBIx::Class::Schema::KiokuDB - Hybrid KiokuDB/DBIx::Class::Schema schema support. SYNOPSIS
Load this component into the schema: package MyApp::DB; use base qw(DBIx::Class::Schema); __PACKAGE__->load_components(qw(Schema::KiokuDB)); __PAKCAGE__->load_namespaces; Then load the DBIx::Class::KiokuDB component into every table that wants to refer to arbitrary KiokuDB objects: package MyApp::DB::Result::Album; use base qw(DBIx::Class::Core); __PACKAGE__->load_components(qw(KiokuDB)); __PACKAGE__->table('album'); __PACKAGE__->add_columns( id => { data_type => "integer" }, title => { data_type => "varchar" }, # the foreign key for the KiokuDB object: metadata => { data_type => "varchar" }, ); __PACKAGE__->set_primary_key('id'); # enable a KiokuDB rel on the column: __PACKAGE__->kiokudb_column('metadata'); Connect to the DSN: my $dir = KiokuDB->connect( 'dbi:SQLite:dbname=:memory:', schema => "MyApp::DB", create => 1, ); # get the connect DBIC schema instance my $schema = $dir->backend->schema; Then you can freely refer to KiokuDB objects from your "Album" class: $dir->txn_do(scope => 1, body => sub { $schema->resultset("Album")->create({ title => "Blah blah", metadata => $any_object, }); }); DESCRIPTION
This class provides the schema definition support code required for integrating an arbitrary DBIx::Class::Schema with KiokuDB::Backend::DBI. REUSING AN EXISTING DBIx::Class SCHEMA The example in the Synopis assumes that you want to first set up a KiokuDB and than link that to some DBIx::Class classes. Another use case is that you already have a configured DBIx::Class Schema and want to tack KiokuDB onto it. The trick here is to make sure to load the KiokuDB schema using "__PACKAGE__->define_kiokudb_schema()" in your Schema class: package MyApp::DB; use base qw(DBIx::Class::Schema); __PACKAGE__->load_components(qw(Schema::KiokuDB)); __PACKAGE__->define_kiokudb_schema(); __PAKCAGE__->load_namespaces; You can now get the KiokuDB directory handle like so: my $dir = $schema->kiokudb_handle; For a complete example take a look at t/autovivify_handle.t. USAGE AND LIMITATIONS
KiokuDB managed objects may hold references to row objects, resultsets (treated as saved searches, or results or cursor state is saved), result source handles, and the schema. Foreign DBIx::Class objects, that is ones that originated from a schema that isn't the underlying schema are currently not supported, but this limitation may be lifted in the future. All DBIC operations which may implicitly cause a lookup of a KIokuDB managed object require live object scope management, just as normal. It is reccomended to use "txn_do" in KiokuDB because that will invoke the appropriate transaction hooks on both layers, as opposed to just in DBIx::Class. SEE ALSO
DBIx::Class::KiokuDB, KiokuDB::Backend::DBI. perl v5.12.4 2011-10-04 DBIx::Class::Schema::KiokuDB(3pm)
Man Page