DBIx-Class-CompressColumns
view release on metacpan or search on metacpan
lib/DBIx/Class/CompressColumns.pm view on Meta::CPAN
$self->throw_exception("could not get an uncompressed scalar:$@")
unless defined( $uncompressed_scalar );
return $uncompressed_scalar;
}
=head2 _compress_column_values
Go through the columns and compress the values that need it.
This method is called by insert and update when automatic compression
is turned on.
=cut
sub _compress_column_values{
my $self = shift;
for my $col (@{$self->compress_auto_columns}) {
warn "in compress_column_values. col: $col";
#don't compress null columns
my $col_v = $self->get_column( $col );
#update column value with encoded value if needed
$self->set_column( $col, $self->_get_compressed_binary( $col_v ) );
}
}
=head2 compress_auto
__PACKAGE__->compress_auto(1);
Turns on and off automatic compression/decompression of columns. When on, this feature makes all
UPDATEs and INSERTs automatically insert a compressed binary into selected columns. SELECTS will
retrieve the decompressed scalar from selected columns.
The default is for compress_auto is to be on.
=head1 EXTENDED METHODS
The following L<DBIx::Class::Row> methods are extended by this module:-
=over 4
=item insert
=cut
sub insert {
my $self = shift;
$self->_compress_column_values if $self->compress_auto;
$self->next::method(@_);
}
=item update
=cut
sub update {
my ( $self, $upd, @rest ) = @_;
if ( ref $upd ) {
for my $col ( @{$self->compress_auto_columns} ) {
$upd->{$col} = compress($upd->{$col},9) if ( exists $upd->{$col} );
}
}
$self->next::method($upd, @rest);
}
=back
=head2 get_column
=cut
sub get_column {
my ( $self, $column ) = @_;
my $value = $self->next::method($column);
if( defined $value ) {
for my $col ( @{$self->compress_auto_columns} ) {
if ( $column eq $col ) {
$value = $self->compress_auto ? uncompress( $value ) : $value;
}
}
}
return $value;
}
=head2 get_columns
=cut
sub get_columns {
my $self = shift;
my %data = $self->next::method(@_);
foreach my $col (keys %data) {
if(defined(my $value = $data{$col}) ) {
for my $col2 ( @{$self->compress_auto_columns} ) {
if ($col eq $col2) {
$value = $self->compress_auto ? uncompress( $value ) : $value;
$data{$col} = $value;
}
}
}
}
return %data;
}
1;
__END__
=head1 SEE ALSO
L<DBIx::Class>,
L<Compress::Zlib>
( run in 1.168 second using v1.01-cache-2.11-cpan-39bf76dae61 )