use File::Path;
use File::Copy;
use Path::Class;
+use DBIx::Class::Carp;
+use namespace::clean;
-use Carp::Clan qw/^DBIx::Class/;
carp 'InflateColumn::File has entered a deprecation cycle. This component '
.'has a number of architectural deficiencies that can quickly drive '
.'your filesystem and database out of sync and is not recommended '
.'DBIC_IC_FILE_NOWARN to a true value to disable this warning.'
unless $ENV{DBIC_IC_FILE_NOWARN};
+
+
__PACKAGE__->load_components(qw/InflateColumn/);
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);
},
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'
);
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
}
# 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});
}
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,
FileColumn requires a hash that contains L<IO::File> 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 => '....'
});
And Place the following in your TT template
Article Subject: [% entry.subject %]
- Uploaded File:
+ Uploaded File:
<a href="/static/files/[% entry.id %]/[% entry.filename.filename %]">File</a>
Body: [% entry.body %]
sub _file_column_callback {}
-=head1 AUTHOR
+=head1 FURTHER QUESTIONS?
-Victor Igumnov
+Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
-=head1 LICENSE
+=head1 COPYRIGHT AND LICENSE
-This library is free software, you can redistribute it and/or modify
-it under the same terms as Perl itself.
+This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
+by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
+redistribute it and/or modify it under the same terms as the
+L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
=cut