From: Arthur Axel 'fREW' Schmidt Date: Sat, 27 Feb 2010 10:43:20 +0000 (-0600) Subject: refactor DeployMethod stuff X-Git-Tag: v0.001000_01~107 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=commitdiff_plain;h=7521a845ba34a0063724e30987b6ab350d5942e5 refactor DeployMethod stuff --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index 8dbc97f..2acfa0d 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -88,9 +88,9 @@ method install { } } -method upgrade { - while ( my $version_list = $self->next_version_set ) { - $self->_upgrade_single_step($version_list); +sub upgrade { + while ( my $version_list = $_[0]->next_version_set ) { + $_[0]->_upgrade_single_step($version_list); } } diff --git a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm index c4e62f5..bc7ed29 100644 --- a/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm +++ b/lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm @@ -6,6 +6,7 @@ use SQL::Translator; require SQL::Translator::Diff; require DBIx::Class::Storage; # loaded for type constraint +with 'DBIx::Class::DeploymentHandler::HandlesDeploy'; use Carp 'carp'; has storage => ( @@ -129,7 +130,8 @@ method _deployment_statements { return $wa ? @ret : $ret[0]; } -method _deploy { +sub _deploy { + my $self = shift; my $storage = $self->storage; my $deploy = sub { @@ -159,7 +161,8 @@ method _deploy { } } -method prepare_install { +sub prepare_install { + my $self = shift; my $schema = $self->schema; my $databases = $self->databases; my $dir = $self->upgrade_directory; @@ -213,7 +216,8 @@ method prepare_install { } } -method prepare_update($version, $preversion) { +sub prepare_update { + my ($self, $version, $preversion) = @_; my $schema = $self->schema; my $databases = $self->databases; my $dir = $self->upgrade_directory; @@ -334,7 +338,8 @@ method _read_sql_file($file) { return \@data; } -method _upgrade_single_step { +sub _upgrade_single_step { + my $self = shift; my @version_set = @{ shift @_ }; my $db_version = $self->db_version; my $upgrade_file = $self->_ddl_filename( diff --git a/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm b/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm new file mode 100644 index 0000000..e899495 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/HandlesDeploy.pm @@ -0,0 +1,13 @@ +package DBIx::Class::DeploymentHandler::HandlesDeploy; +use Moose::Role; + +requires 'prepare_install'; +requires 'prepare_update'; +requires '_upgrade_single_step'; +requires '_deploy'; + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/lib/DBIx/Class/DeploymentHandler/WithSqltDeployMethod.pm b/lib/DBIx/Class/DeploymentHandler/WithSqltDeployMethod.pm index b81e084..c100265 100644 --- a/lib/DBIx/Class/DeploymentHandler/WithSqltDeployMethod.pm +++ b/lib/DBIx/Class/DeploymentHandler/WithSqltDeployMethod.pm @@ -4,22 +4,10 @@ use Moose::Role; use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator; has deploy_method => ( - -# < mst> isa => 'DBIx::Class::DeploymentHandler::SqltDeployMethod', -# < mst> should be -# < mst> does => -# < mst> and that role should supply those methods -# < mst> then you can pass handles => as well - - isa => 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator', + does => 'DBIx::Class::DeploymentHandler::HandlesDeploy', is => 'ro', lazy_build => 1, - handles => [qw{ - _deploy - prepare_install - prepare_update - _upgrade_single_step - }], + handles => 'DBIx::Class::DeploymentHandler::HandlesDeploy', ); sub _build_deploy_method {