Port to Moo
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionHandler / DatabaseToSchemaVersions.pm
1 package DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions;
2 use Moo;
3 use Sub::Quote 'quote_sub';
4 use MooX::Types::MooseLike::Base qw(Str Bool);
5
6 # ABSTRACT: Go straight from Database to Schema version
7
8 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
9
10 has schema_version => (
11   isa      => Str,
12   is       => 'ro',
13   required => 1,
14 );
15
16 has database_version => (
17   isa      => Str,
18   is       => 'ro',
19   required => 1,
20 );
21
22 has to_version => ( # configuration
23   is   => 'ro',
24   isa  => Str,
25   builder => '_build_to_version',
26 );
27
28 sub _build_to_version { $_[0]->schema_version }
29
30 has once => (
31   is      => 'rw',
32   isa     => Bool,
33   default => quote_sub(q{undef}),
34 );
35
36 sub next_version_set {
37   my $self = shift;
38   return undef
39     if $self->once;
40
41   $self->once(!$self->once);
42   return undef
43     if $self->database_version eq $self->to_version;
44   return [$self->database_version, $self->to_version];
45 }
46
47 sub previous_version_set {
48   my $self = shift;
49   return undef
50     if $self->once;
51
52   $self->once(!$self->once);
53   return undef
54     if $self->database_version eq $self->to_version;
55   return [$self->database_version, $self->to_version];
56 }
57
58 1;
59
60 # vim: ts=2 sw=2 expandtab
61
62 __END__
63
64 =head1 SEE ALSO
65
66 This class is an implementation of
67 L<DBIx::Class::DeploymentHandler::HandlesVersioning>.  Pretty much all the
68 documentation is there.