X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FInflateColumn%2FFile.pm;h=d4984f83d0306b7d84f40a3c709a1063223797e6;hb=3440100bc0455cf0e7ccbba03754a29ad26ec6d1;hp=634bafc80f58e3f384482a405354644c2fe729d6;hpb=9c1700e39e6ee002d9294c0d988882d1f0d7d86f;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/InflateColumn/File.pm b/lib/DBIx/Class/InflateColumn/File.pm index 634bafc..d4984f8 100644 --- a/lib/DBIx/Class/InflateColumn/File.pm +++ b/lib/DBIx/Class/InflateColumn/File.pm @@ -6,7 +6,7 @@ use base 'DBIx::Class'; use File::Path; use File::Copy; use Path::Class; -use Carp::Clan qw/^DBIx::Class/; +use DBIx::Class::Carp; use namespace::clean; carp 'InflateColumn::File has entered a deprecation cycle. This component ' @@ -29,7 +29,7 @@ sub register_column { return unless defined($info->{is_file_column}); $self->inflate_column($column => { - inflate => sub { + inflate => sub { my ($value, $obj) = @_; $obj->_inflate_file_column($column, $value); }, @@ -43,10 +43,14 @@ sub register_column { sub _file_column_file { my ($self, $column, $filename) = @_; - my $column_info = $self->column_info($column); + my $column_info = $self->result_source->column_info($column); return unless $column_info->{is_file_column}; + # DO NOT CHANGE + # This call to id() is generally incorrect - will not DTRT on + # multicolumn key. However changing this may introduce + # backwards-comp regressions, thus leaving as is my $id = $self->id || $self->throw_exception( 'id required for filename generation' ); @@ -60,8 +64,10 @@ sub _file_column_file { sub delete { my ( $self, @rest ) = @_; - for ( $self->columns ) { - if ( $self->column_info($_)->{is_file_column} ) { + my $colinfos = $self->result_source->columns_info; + + for ( keys %$colinfos ) { + if ( $colinfos->{$_}{is_file_column} ) { rmtree( [$self->_file_column_file($_)->dir], 0, 0 ); last; # if we've deleted one, we've deleted them all } @@ -75,9 +81,11 @@ sub insert { # cache our file columns so we can write them to the fs # -after- we have a PK + my $colinfos = $self->result_source->columns_info; + my %file_column; - for ( $self->columns ) { - if ( $self->column_info($_)->{is_file_column} ) { + for ( keys %$colinfos ) { + if ( $colinfos->{$_}{is_file_column} ) { $file_column{$_} = $self->$_; $self->store_column($_ => $self->$_->{filename}); } @@ -155,7 +163,7 @@ In your L table class: data_type => "varchar", is_file_column => 1, file_column_path =>'/tmp/uploaded_files', - # or for a Catalyst application + # or for a Catalyst application # file_column_path => MyApp->path_to('root','static','files'), default_value => undef, is_nullable => 1, @@ -169,11 +177,11 @@ In your L class: FileColumn requires a hash that contains L as handle and the file's name as name. - my $entry = $c->model('MyAppDB::Articles')->create({ + my $entry = $c->model('MyAppDB::Articles')->create({ subject => 'blah', - filename => { - handle => $c->req->upload('myupload')->fh, - filename => $c->req->upload('myupload')->basename + filename => { + handle => $c->req->upload('myupload')->fh, + filename => $c->req->upload('myupload')->basename }, body => '....' }); @@ -183,7 +191,7 @@ name as name. And Place the following in your TT template Article Subject: [% entry.subject %] - Uploaded File: + Uploaded File: File Body: [% entry.body %]