1 package DBIx::Class::Fixtures::External::File;
6 use File::Spec::Functions 'catfile', 'splitpath';
7 use File::Path 'mkpath';
10 my ($class, $path) = @_;
11 open(my $fh, '<', $path)
12 || die "can't open $path: $!";
18 my ($class, $path, $content) = @_;
19 open (my $fh, '>', $path)
20 || die "can't open $path: $!";
26 my ($class, $key, $args) = @_;
27 my $path = catfile($args->{path}, $key);
28 return $class->_load($path);
32 my ($class, $key, $content, $args) = @_;
33 my ($vol, $directory, $file) = splitpath catfile($args->{path}, $key);
34 mkpath($directory) unless -d $directory;
35 my $path = catfile($vol, $directory, $file);
36 $class->_save($path, $content);
43 DBIx::Class::Fixtures::External::File - save and restore external data
47 my $fixtures = DBIx::Class::Fixtures
49 config_dir => 't/var/configs',
50 config_attrs => { photo_dir => './t/var/files' });
59 "args": {"path":"__ATTR(photo_dir)__"}
67 Sometimes your database fields are pointers to external data. The classic
68 example is you are using L<DBIx::Class::InflateColumn::FS> to manage blob
69 data. In these cases it may be desirable to backup and restore the external
72 This module performs this function and can also serve as an example for your
73 possible custom needs.
77 This module defines the following methods
81 Accepts: Value of Database Field, $args
83 Given the value of a database field (which is some sort of pointer to the location
84 of an actual file, and a hashref of args (passed in the args key of your config
85 set), slurp up the file and return to to be saved in the fixure.
89 Accepts: Value of Database Field, Content, $args
91 Given the value of a database field, some blob content and $args, restore the
92 file to the filesystem
96 See L<DBIx::Class::Fixtures> for author information.
100 See L<DBIx::Class::Fixtures> for contributor information.
104 See L<DBIx::Class::Fixtures> for license information.