SYNOPSIS

  package MySchema::Table;
  use base 'DBIx::Class';

  _\|_PACKAGE_\|_->load_components('InflateColumn::Serializer', 'Core');
  _\|_PACKAGE_\|_->add_columns(
    'data_column' => {
      'data_type' => 'VARCHAR',
      'size'      => 255,
      'serializer_class'   => 'JSON'
    }
  );

Then in your code...

my $struct = { 'I' => { 'am' => 'a struct' }; $obj->data_column($struct); $obj->update;

And you can recover your data structure with:

my $obj = ...->find(...); my $struct = $obj->data_column;

The data structures you assign to \*(L"data_column\*(R" will be saved in the database in \s-1JSON\s0 format.

DESCRIPTION

These modules help you store and access serialized data structures in the columns of your \s-1DB\s0 from your DBIx::Classes. They are inspired from the DBIx::Class::Manual::FAQ and the \s-1DBIC\s0 test suite, and provide a bit more protection than the inflators proposed in the \s-1FAQ\s0. The intention is to provide a suite of well proven and reusable inflators and deflators to complement DBIx::Class.

Added features for these inflators are: - throw an exception if the serialization doesn't fit in the field - throw an exception if the deserialization results in an error

Right now there are three serializers: - Storable - \s-1JSON\s0 - \s-1YAML\s0

USAGE

1. Choose your serializer: \s-1JSON\s0, \s-1YAML\s0 or Storable

2. Add 'InflateColumn::Serializer' into the load_components of your table class

3. add 'serializer_class' => \s-1SERIALIZER\s0 to the properties of the column that you want to (de/i)nflate

   with the \s-1SERIALIZER\s0 class.

NOTES

As stated in the \s-1DBIC\s0 \s-1FAQ:\s0 \*(L"Be careful not to overuse this capability, however. If you find yourself depending more and more on some data within the inflated column, then it may be time to factor that data out.\*(R"

AUTHOR

Jose Luis Martinez CPAN ID: JLMARTIN CAPSiDE [email protected] http://www.pplusdomain.net

COPYRIGHT

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 \s-1LICENSE\s0 file included with this module.

THANKS

Matt S Trout for his valuable feedback

Ask Bjorn Hansen

RELATED TO DBIx::Class::InflateColumn::Serializer…

DBIx::Class, DBIx::Class::Manual::FAQ