From: Arthur Axel 'fREW' Schmidt Date: Sat, 20 Mar 2010 20:06:47 +0000 (-0500) Subject: no need for MSS for simple modules X-Git-Tag: v0.001000_01~74 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=58a5e27f74f7bacf7d5695563ff91deb095bff07;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git no need for MSS for simple modules fix some logic errors --- diff --git a/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm b/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm index 62ba103..c87b36e 100644 --- a/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm +++ b/lib/DBIx/Class/DeploymentHandler/VersionHandler/ExplicitVersions.pm @@ -1,6 +1,5 @@ package DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions; use Moose; -use Method::Signatures::Simple; use Carp 'croak'; with 'DBIx::Class::DeploymentHandler::HandlesVersioning'; @@ -36,6 +35,9 @@ has ordered_versions => ( croak 'to_version not in ordered_versions' unless grep { $to_version eq $_ } @{ $_[1] }; + croak 'database_version not in ordered_versions' + unless grep { $db_version eq $_ } @{ $_[1] }; + for (@{ $_[1] }) { return if $_ eq $db_version; croak 'to_version is before database version in ordered_versions' @@ -50,9 +52,10 @@ has _version_idx => ( lazy_build => 1, ); -method _inc_version_idx { $self->_version_idx($self->_version_idx + 1 ) } +sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) } -method _build__version_idx { +sub _build__version_idx { + my $self = shift; my $start = $self->database_version; my $idx = 0; for (@{$self->ordered_versions}) { @@ -60,21 +63,21 @@ method _build__version_idx { if $_ eq $self->database_version; $idx++; } - croak 'database version not found in ordered_versions!'; } -sub next_version_set { # sub instead of method because of when roles get composed +sub next_version_set { my $self = shift; return undef if $self->ordered_versions->[$self->_version_idx] eq $self->to_version; + # this should never get in infinite loops because we ensure + # that the database version is in the list in the version_idx + # builder my $next_idx = $self->_inc_version_idx; return [ $self->ordered_versions->[$next_idx - 1], $self->ordered_versions->[$next_idx ], - ] if $next_idx <= $#{ $self->ordered_versions }; - - croak 'this should never happen'; + ]; } __PACKAGE__->meta->make_immutable; diff --git a/t/version_handlers/explict_versions.t b/t/version_handlers/explict_versions.t index c6d0d98..4eb4b6a 100644 --- a/t/version_handlers/explict_versions.t +++ b/t/version_handlers/explict_versions.t @@ -76,7 +76,7 @@ my $versions = [map "$_.0", 0..100]; dies_ok { my $vh = ExplicitVersions->new({ ordered_versions => $versions, - schema_version => '1.0', + schema_version => '2.0', database_version => '1.1', }); $vh->next_vesion_set