From: Victor Igumnov Date: Sun, 21 Jan 2007 00:48:49 +0000 (+0000) Subject: changed FileColumn to InflateColumn::File X-Git-Tag: v0.08010~150^2~99 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28d4067a8514340167194b3397931a6cdb93be26;p=dbsrgits%2FDBIx-Class.git changed FileColumn to InflateColumn::File --- diff --git a/lib/DBIx/Class/FileColumn.pm b/lib/DBIx/Class/InflateColumn/File.pm similarity index 78% rename from lib/DBIx/Class/FileColumn.pm rename to lib/DBIx/Class/InflateColumn/File.pm index 757d75a..1d76bef 100644 --- a/lib/DBIx/Class/FileColumn.pm +++ b/lib/DBIx/Class/InflateColumn/File.pm @@ -1,4 +1,4 @@ -package DBIx::Class::FileColumn; +package DBIx::Class::File; use strict; use warnings; @@ -7,31 +7,25 @@ use File::Path; use File::Copy; use IO::File; -sub inflate_result { - my $self = shift; - my $ret = $self->next::method(@_); - - $self->_inflate_file_column($ret); - return $ret; -} +__PACKAGE__->load_components(qw/InflateColumn/); -sub insert { - my ( $self, @rest ) = @_; - my ( $file, @column_names ) = $self->_load_file_column_information; - my $ret = $self->next::method(@rest); - $self->_save_file_column( $file, $ret, @column_names ); - return $ret; +sub register_column { + my ($self, $column, $info, @rest) = @_; + $self->next::method($column, $info, @rest); + return unless defined($info->{is_file_column}); + $self->inflate_column( + $column => + { + inflate => $self->_inflate_file_column, + deflate => sub { + my ( $file, @column_names ) = $self->_load_file_column_information; + $self->_save_file_column( $file, $self, @column_names ); + }, + } + ); } -sub update { - my ($self, @rest ) = @_; - - my ( $file, @column_names ) = $self->_load_file_column_information; - my $ret = $self->next::method(@rest); - $self->_save_file_column( $file, $ret, @column_names ); - return $ret; -} sub delete { my ( $self, @rest ) = @_; @@ -53,21 +47,20 @@ sub delete { sub _inflate_file_column { my $self = shift; - my $ret = shift; my @column_names = $self->columns; for(@column_names) { - if ( $ret->column_info($_)->{is_file_column} ) { + if ( $self->column_info($_)->{is_file_column} ) { # make sure everything checks out - unless (defined $ret->$_) { + unless (defined $self->$_) { # if something is wrong set it to undef - $ret->$_(undef); + $self->$_(undef); next; } my $fs_file = - File::Spec->catfile( $ret->column_info($_)->{file_column_path}, - $ret->id, $ret->$_ ); - $ret->$_({handle => new IO::File($fs_file, "r"), filename => $ret->$_}); + File::Spec->catfile( $self->column_info($_)->{file_column_path}, + $self->id, $self->$_ ); + $self->$_({handle => new IO::File($fs_file, "r"), filename => $self->$_}); } } } @@ -133,17 +126,17 @@ sub _file_column_callback { =head1 NAME -DBIx::Class::FileColumn - FileColumn map files from the Database to the filesystem. +DBIx::Class::InflateColumn::File - map files from the Database to the filesystem. =head1 DESCRIPTION -FileColumn +InflateColumn::File =head1 SYNOPSIS In your L table class: - __PACKAGE__->load_components( "PK::Auto", "FileColumn", "Core" ); + __PACKAGE__->load_components( "PK::Auto", "InflateColumn::File", "Core" ); # define your columns __PACKAGE__->add_columns( diff --git a/t/96file_column.t b/t/96file_column.t index 25d9149..4773861 100644 --- a/t/96file_column.t +++ b/t/96file_column.t @@ -8,11 +8,8 @@ use IO::File; my $schema = DBICTest->init_schema(); -plan tests => 2; +plan tests => 1; - -eval { $schema->resultset('FileColumn')->create({file=>'wrong set'}) }; -ok($@, 'FileColumn checking for checks against bad sets'); -my $fh = new IO::File('t/96file_column.pm','r'); -eval { $schema->resultset('FileColumn')->create({file => {handle => $fh, filename =>'96file_column.pm'}})}; +my $fh = new IO::File('t/96file_column.t','r'); +eval { $schema->resultset('FileColumn')->create({file => {handle => $fh, filename =>'96file_column.t'}})}; ok(!$@,'FileColumn checking if file handled properly.'); diff --git a/t/lib/DBICTest/Schema/FileColumn.pm b/t/lib/DBICTest/Schema/FileColumn.pm index 22d3a1a..a6d768f 100644 --- a/t/lib/DBICTest/Schema/FileColumn.pm +++ b/t/lib/DBICTest/Schema/FileColumn.pm @@ -5,7 +5,7 @@ use strict; use warnings; use base qw/DBIx::Class::Core/; -__PACKAGE__->load_components(qw/FileColumn/); +__PACKAGE__->load_components(qw/InflateColumn::File/); __PACKAGE__->table('file_columns');