no need for MSS for simple modules
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionHandler / ExplicitVersions.pm
index 191ac1a..c87b36e 100644 (file)
@@ -1,10 +1,29 @@
 package DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
 use Moose;
-use Method::Signatures::Simple;
 use Carp 'croak';
 
 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
 
+has schema_version => (
+  isa      => 'Str',
+  is       => 'ro',
+  required => 1,
+);
+
+has database_version => (
+  isa      => 'Str',
+  is       => 'ro',
+  required => 1,
+);
+
+has to_version => ( # configuration
+  is         => 'ro',
+  lazy_build => 1, # builder comes from another role...
+                   # which is... probably not how we want it
+);
+
+sub _build_to_version { $_[0]->schema_version }
+
 has ordered_versions => (
   is       => 'ro',
   isa      => 'ArrayRef',
@@ -16,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'
@@ -30,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}) {
@@ -40,22 +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;
-  if ( $next_idx <= $#{ $self->ordered_versions }) {
-    return [
-      $self->ordered_versions->[$next_idx - 1],
-      $self->ordered_versions->[$next_idx    ],
-    ]
-  } else {
-    return undef
-  }
+  return [
+    $self->ordered_versions->[$next_idx - 1],
+    $self->ordered_versions->[$next_idx    ],
+  ];
 }
 
 __PACKAGE__->meta->make_immutable;