11 use Path::Class qw/file/;
14 local $ENV{DBIC_IC_FILE_NOWARN} = 1;
16 package DBICTest::Schema::FileColumn;
20 use base qw/DBICTest::BaseResult/;
22 use File::Temp qw/tempdir/;
24 __PACKAGE__->load_components (qw/InflateColumn::File/);
25 __PACKAGE__->table('file_columns');
27 __PACKAGE__->add_columns(
28 id => { data_type => 'integer', is_auto_increment => 1 },
30 data_type => 'varchar',
32 file_column_path => tempdir(CLEANUP => 1),
37 __PACKAGE__->set_primary_key('id');
39 DBICTest::Schema->load_classes('FileColumn');
41 my $schema = DBICTest->init_schema;
45 if (not $ENV{DBICTEST_SQLT_DEPLOY}) {
46 $schema->storage->dbh->do(<<'EOF');
47 CREATE TABLE file_columns (
48 id INTEGER PRIMARY KEY,
54 my $rs = $schema->resultset('FileColumn');
55 my $source_file = file(__FILE__);
56 my $fname = $source_file->basename;
57 my $fh = $source_file->open('r') or die "failed to open $source_file: $!\n";
59 $rs->create({ file => { handle => $fh, filename => $fname } })
61 is ( $@, '', 'created' );
66 $fc->column_info('file')->{file_column_path},
68 $fc->file->{filename},
70 ok ( -e $storage, 'storage exists' );
73 $fc = $rs->find({ id => $fc->id });
75 is ( $fc->file->{filename}, $fname, 'filename matches' );
76 ok ( compare($storage, $source_file) == 0, 'file contents matches' );
79 my $new_fname = 'File.pm';
80 my $new_source_file = file(qw/lib DBIx Class InflateColumn File.pm/);
81 my $new_storage = file(
82 $fc->column_info('file')->{file_column_path},
86 $fh = $new_source_file->open('r') or die "failed to open $new_source_file: $!\n";
88 $fc->file({ handle => $fh, filename => $new_fname });
92 local $TODO = 'design change required';
93 ok ( ! -e $storage, 'old storage does not exist' );
96 ok ( -e $new_storage, 'new storage exists' );
99 $fc = $rs->find({ id => $fc->id });
101 is ( $fc->file->{filename}, $new_fname, 'new filname matches' );
102 ok ( compare($new_storage, $new_source_file) == 0, 'new content matches' );
104 if ($^O eq 'MSWin32') {
105 close $fc->file->{handle}; # can't delete open files on Win32
109 ok ( ! -e $storage, 'storage deleted' );
111 $fh = $source_file->openr or die "failed to open $source_file: $!\n";
112 $fc = $rs->create({ file => { handle => $fh, filename => $fname } });
115 $fc->discard_changes;
118 $fc->column_info('file')->{file_column_path},
120 $fc->file->{filename},
124 local $TODO = 'need resultset delete override to delete_all';
126 ok ( ! -e $storage, 'storage does not exist after $rs->delete' );