Test::DBIx::Class::FixtureCommand::PopulateMore - Install fixtures using PopulateMore


Test-DBIx-Class documentation Contained in the Test-DBIx-Class distribution.

Index


Code Index:

NAME

Top

Test::DBIx::Class::FixtureCommand::PopulateMore - Install fixtures using PopulateMore

SYNOPSIS

Top

	my $command = Test::DBIx::Class::FixtureComand::PopulateMore->new(schema=>$schema);
	$command->install_fixtures($fixtures);

DESCRIPTION

Top

This uses the DBIx::Class::Schema::PopulateMore to install fixtures. Please review the documentation for that module for more.

METHODS

Top

This class defines the following methods

install_fixtures

Takes an Array or ArrayRef of arguments and installs them into your target database. Returns as DBIx::Class::Schema::PopulateMore.

AUTHOR

Top

John Napiorkowski <jjnapiork@cpan.org>

COPYRIGHT & LICENSE

Top


Test-DBIx-Class documentation Contained in the Test-DBIx-Class distribution.

package Test::DBIx::Class::FixtureCommand::PopulateMore; {

	use Moose;
	use Test::More ();
	use DBIx::Class::Schema::PopulateMore::Command;
	with 'Test::DBIx::Class::Role::FixtureCommand';

	sub install_fixtures {
		my ($self, $arg, @rest) = @_;
		my $builder = $self
			->schema_manager
			->builder;

		$builder->croak("Argument is required.")
		  unless $arg;

		my @args;
		if(ref $arg && ref $arg eq 'ARRAY') {
			@args = @$arg;
		}
		elsif(ref $arg && ref $arg eq 'HASH') {
			@args = %$arg;
		}
		else {
			@args = ($arg, @rest);
		}

		my @definitions;
		while(@args) {
			my $next = shift(@args);
			if( (ref $next) && (ref $next eq 'HASH') ) {
				push @definitions, $next;
			} else {
				my $value = shift(@args);
				push @definitions, {$next => $value};
			}
		}

		my ($command, %return);
		
		eval {
			$command = DBIx::Class::Schema::PopulateMore::Command->new(
				definitions=>[@definitions],
				schema=>$self->schema_manager->schema,
				exception_cb=>sub {
					$builder->croak(@_);
				},
			);
		}; if ($@) {
			Test::More::fail("Can't create command class: $@");
		} else {
			eval {
				%return = $command->execute;
			}; if ($@) {
				Test::More::fail("Can't install fixtures: $@");
			}
		}		

		return %return;
	}
} 1;

__END__