Fold column_info() into columns_info()
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / InflateColumn / File.pm
index aa06dbc..34db2ed 100644 (file)
@@ -2,10 +2,17 @@ package DBIx::Class::InflateColumn::File;
 
 use strict;
 use warnings;
+
+# check deps
+BEGIN {
+  require DBIx::Class::Optional::Dependencies;
+  if (my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('ic_file') ) {
+    die "The following extra modules are required for DBIx::Class::InflateColumn::File: $missing\n";
+  }
+}
+
 use base 'DBIx::Class';
-use File::Path;
 use File::Copy;
-use Path::Class;
 use DBIx::Class::Carp;
 use namespace::clean;
 
@@ -20,7 +27,6 @@ carp 'InflateColumn::File has entered a deprecation cycle. This component '
 unless $ENV{DBIC_IC_FILE_NOWARN};
 
 
-
 __PACKAGE__->load_components(qw/InflateColumn/);
 
 sub register_column {
@@ -43,10 +49,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->columns_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,9 +70,11 @@ sub _file_column_file {
 sub delete {
     my ( $self, @rest ) = @_;
 
-    for ( $self->columns ) {
-        if ( $self->column_info($_)->{is_file_column} ) {
-            rmtree( [$self->_file_column_file($_)->dir], 0, 0 );
+    my $colinfos = $self->result_source->columns_info;
+
+    for ( keys %$colinfos ) {
+        if ( $colinfos->{$_}{is_file_column} ) {
+            $self->_file_column_file($_)->dir->rmtree;
             last; # if we've deleted one, we've deleted them all
         }
     }
@@ -75,9 +87,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});
         }
@@ -108,7 +122,7 @@ sub _save_file_column {
     return unless ref $value;
 
     my $fs_file = $self->_file_column_file($column, $value->{filename});
-    mkpath [$fs_file->dir];
+    $fs_file->dir->mkpath;
 
     # File::Copy doesn't like Path::Class (or any for that matter) objects,
     # thus ->stringify (http://rt.perl.org/rt3/Public/Bug/Display.html?id=59650)
@@ -206,14 +220,16 @@ Method made to be overridden for callback purposes.
 
 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