DBIx-Class-Fixtures
view release on metacpan or search on metacpan
- Support more Postgresql types for datetime_relative (added TIME, DATE,
INTERVAL, TIMESTAMP)
- If $result_source->column_info defines a sequence, make sure we properly
set that sequence to whatever the max value currently is.
1.001015
- ::External::File makes the path if its missing
1.001014
- Allow you to perform value substitutions inside config-sets
- Added a framework to allow you to backup / restore data external to the
database as part of your fixtures. Added an external handler for File
based data, and docs and tests for this.
1.001013
- fixed functionality in last release by more deeply cloning parameters, which
prevents bad things when parameters get deleted in the wrong places. Also
be sure we clear state properly after a dump.
1.001012
- Added new method 'available_config_sets' which returns and caches a list of
lib/DBIx/Class/Fixtures.pm view on Meta::CPAN
in this case.
This value will be inherited by all fetches in this set. This is not true for
the has_many attribute.
=head2 external
In some cases your database information might be keys to values in some sort of
external storage. The classic example is you are using L<DBIx::Class::InflateColumn::FS>
to store blob information on the filesystem. In this case you may wish the ability
to backup your external storage in the same way your database data. The L</external>
attribute lets you specify a handler for this type of issue. For example:
{
"sets": [{
"class": "Photo",
"quantity": "all",
"external": {
"file": {
"class": "File",
"args": {"path":"__ATTR(photo_dir)__"}
}
}
}]
}
This would use L<DBIx::Class::Fixtures::External::File> to read from a directory
where the path to a file is specified by the C<file> field of the C<Photo> source.
We use the uninflated value of the field so you need to completely handle backup
and restore. For the common case we provide L<DBIx::Class::Fixtures::External::File>
and you can create your own custom handlers by placing a '+' in the namespace:
"class": "+MyApp::Schema::SomeExternalStorage",
Although if possible I'd love to get patches to add some of the other common
types (I imagine storage in MogileFS, Redis, etc or even Amazon might be popular.)
See L<DBIx::Class::Fixtures::External::File> for the external handler interface.
lib/DBIx/Class/Fixtures.pm view on Meta::CPAN
foreach my $field (keys %{$set->{external}}) {
my $key = $ds{$field};
my ($plus, $class) = ( $set->{external}->{$field}->{class}=~/^(\+)*(.+)$/);
my $args = $set->{external}->{$field}->{args};
$class = "DBIx::Class::Fixtures::External::$class" unless $plus;
eval "use $class";
$ds{external}->{$field} =
encode_base64( $class
->backup($key => $args),'');
}
}
# mess with dates if specified
if ($set->{datetime_relative}) {
my $formatter= eval {$object->result_source->schema->storage->datetime_parser};
unless (!$formatter) {
my $dt;
if ($set->{datetime_relative} eq 'today') {
$dt = DateTime->today;
lib/DBIx/Class/Fixtures/External/File.pm view on Meta::CPAN
}
sub _save {
my ($class, $path, $content) = @_;
open (my $fh, '>', $path)
|| die "can't open $path: $!";
print $fh $content;
close($fh);
}
sub backup {
my ($class, $key, $args) = @_;
my $path = catfile($args->{path}, $key);
return $class->_load($path);
}
sub restore {
my ($class, $key, $content, $args) = @_;
my $path = catfile($args->{path}, $key);
my ($vol, $directory, $file) = splitpath($path);
mkpath($directory) unless -d $directory;
lib/DBIx/Class/Fixtures/External/File.pm view on Meta::CPAN
"args": {"path":"__ATTR(photo_dir)__"}
}
}
}]
}
=head1 DESCRIPTION
Sometimes your database fields are pointers to external data. The classic
example is you are using L<DBIx::Class::InflateColumn::FS> to manage blob
data. In these cases it may be desirable to backup and restore the external
data via fixtures.
This module performs this function and can also serve as an example for your
possible custom needs.
=head1 METHODS
This module defines the following methods
=head2 backup
Accepts: Value of Database Field, $args
Given the value of a database field (which is some sort of pointer to the location
of an actual file, and a hashref of args (passed in the args key of your config
set), slurp up the file and return to to be saved in the fixure.
=head2 restore
Accepts: Value of Database Field, Content, $args
( run in 1.111 second using v1.01-cache-2.11-cpan-49f99fa48dc )