ObjectDB::InflateColumn - automatically create references from column data
package MyApp::ObjectDB; use base qw(ObjectDB); use ObjectDB::InflateColumn; ..... 1; # in your table classes package MyApp::ORM::SomeTokenAction; use base 'MyApp::ObjectDB'; # some schema description __PACKAGE__->schema( table => 'some_token_action', columns => [qw/id token .... data/], primary_keys => ['id'], auto_increment => 'id', ); use JSON; my $json = JSON->new; # describe infalte __PACKAGE__->schema->inflate_column( 'data', { inflate => sub { $json->allow_nonref->encode($_[0]) }, deflate => sub { $json->utf8(1)->decode($_[0]) }, } ); # ============================================================= # in main code package main; use MyApp::ORM::SomeTokenAction; # create entity my $token_entity = MyApp::ORM::SomeTokenAction->new(token => ...); $token_entity->inflate_column('data', {some_key => 'some_value'}); $token_entity->column('data'); # string '{"some_key":"some_value"}' $token_entity->inflate_column('data'); # real hash {"some_key":"some_value"} $token_entity->create; # or load my $token_entitys = MyApp::ORM::SomeTokenAction->find(where => [token => ...]); $token_entitys->[0]->column('data'); # string '{"some_key":"some_value"}' $token_entitys->[0]->inflate_column('data'); # real hash {"some_key":"some_value"} # or something else from ObjectDB
There's similar DBIx::Class::InflateColumn, but created for ObjectDB.
This module make export some methods to ObjectDB::Schema and ObjectDB.
By default 'inflate' and 'deflate' will be set to sub{ $_[0] }.
Accessor for inflate column.
git@github.com:mrRico/p5-ObjectDB-InflateColumn.git
ObjectDB
mr.Rico <catamoose at yandex.ru>
To install ObjectDB::InflateColumn, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ObjectDB::InflateColumn
CPAN shell
perl -MCPAN -e shell install ObjectDB::InflateColumn
For more information on module installation, please visit the detailed CPAN module installation guide.