/usr/share/perl5/DBIx/Class/InflateColumn/Serializer/Storable.pm is in libdbix-class-inflatecolumn-serializer-perl 0.06-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | package DBIx::Class::InflateColumn::Serializer::Storable;
{
$DBIx::Class::InflateColumn::Serializer::Storable::VERSION = '0.06';
}
=head1 NAME
DBIx::Class::InflateColumn::Serializer::Storable - Storable Inflator
=head1 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' => 'Storable'
}
);
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 "data_column" will be saved in the database in Storable format.
=cut
use strict;
use warnings;
use Storable qw//;
use Carp;
=over 4
=item get_freezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that serializes
the data passed to it. Returns a coderef.
=cut
sub get_freezer{
my ($class, $column, $info, $args) = @_;
if (defined $info->{'size'}){
my $size = $info->{'size'};
return sub {
my $s = Storable::nfreeze(shift);
croak "serialization too big" if (length($s) > $size);
return $s;
};
} else {
return sub {
return Storable::nfreeze(shift);
};
}
}
=item get_unfreezer
Called by DBIx::Class::InflateColumn::Serializer to get the routine that deserializes
the data stored in the column. Returns a coderef.
=back
=cut
sub get_unfreezer {
return sub {
my $value = shift;
# Storable returns undef if the datastructure couldn't be thawed.
# Other deserializers throw exceptions, so we'll do the same.
# If the column had a NULL value, then we return it (don't want to die)
return undef if (not defined $value);
my $s = Storable::thaw($value);
croak "Storable couldn't thaw the value" if (not defined $s);
return $s;
};
}
1;
|