From: John Napiorkowski Date: Wed, 2 Mar 2011 15:04:15 +0000 (-0500) Subject: new functionality X-Git-Tag: 1.001012~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d9b65413b90cf12014ce931c98c169c4b6f8e7f3;p=dbsrgits%2FDBIx-Class-Fixtures.git new functionality --- diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index b946e83..630e1f6 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -26,15 +26,15 @@ __PACKAGE__->mk_group_accessors( 'simple' => qw/config_dir =head1 VERSION -Version 1.001011 +Version 1.001012 =cut -our $VERSION = '1.001011'; +our $VERSION = '1.001012'; =head1 NAME -DBIx::Class::Fixtures +DBIx::Class::Fixtures - Dump data and repopulate a database using rules =head1 SYNOPSIS @@ -434,6 +434,22 @@ sub new { return $self; } +=head2 available_config_sets + +Returns a list of all the config sets found in the L. These will +be a list of the json based files containing dump rules. + +=cut + +my @config_sets; +sub available_config_sets { + @config_sets = scalar(@config_sets) ? @config_sets : map { + $_->basename; + } grep { + -f $_ && $_=~/json$/; + } dir((shift)->config_dir)->children; +} + =head2 dump =over 4 @@ -923,6 +939,40 @@ sub _read_sql { return \@data; } +=head2 dump_all_config_sets + +Works just like L but instead of specifying a single json config set +located in L we dump each set in turn to the specified directory. + +The parameters are the same as for L except instead of a C +parameter we have a C which is a coderef expected to return +a scalar that is a root directory where we will do the actual dumping. This +coderef get three arguments: C<$self>, C<$params> and C<$set_name>. For +example: + + $fixture->dump_all_config_sets({ + schema => $schema, + directory_template => sub { + my ($fixture, $params, $set) = @_; + return File::Spec->catdir('var', 'fixtures', $params->{schema}->version, $set); + }, + }); + +=cut + +sub dump_all_config_sets { + my ($self, $params) = @_; + my @available_config_sets = $self->available_config_sets; + my $directory_template = delete $params->{directory_template} || + DBIx::Class::Exception->throw("'directory_template is required parameter"); + + for my $set (@available_config_sets) { + local($self,$params); + $params->{directory} = $directory_template->($self, $params, $set); + $self->dump($params) + } +} + =head2 populate =over 4