File Coverage

blib/lib/DBIx/Class/DeploymentHandler/VersionHandler/DatabaseToSchemaVersions.pm
Criterion Covered Total %
statement 9 14 64.2
branch 4 8 50.0
condition n/a
subroutine 3 4 75.0
pod 0 2 0.0
total 16 28 57.1


line stmt bran cond sub pod time code
1             package DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions;
2             $DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions::VERSION = '0.002232';
3 2     2   164130 use Moose;
  2         462142  
  2         16  
4              
5             # ABSTRACT: Go straight from Database to Schema version
6              
7             with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
8              
9             has schema_version => (
10             is => 'ro',
11             required => 1,
12             );
13              
14             has initial_version => (
15             isa => 'Str',
16             is => 'ro',
17             required => 1,
18             );
19              
20             has to_version => ( # configuration
21             is => 'ro',
22             isa => 'Str',
23             lazy_build => 1,
24             );
25              
26 3     3   135 sub _build_to_version { $_[0]->schema_version }
27              
28             has once => (
29             is => 'rw',
30             isa => 'Bool',
31             default => undef,
32             );
33              
34             # provide backwards compatibility for initial_version/database_version
35             around BUILDARGS => sub {
36             my $orig = shift;
37             my $class = shift;
38              
39             my $args = $class->$orig(@_);
40             $args->{initial_version} = $args->{database_version}
41             if exists $args->{database_version} && !exists $args->{initial_version};
42             return $args;
43             };
44              
45             sub next_version_set {
46 11     11 0 3193 my $self = shift;
47             return undef
48 11 100       592 if $self->once;
49              
50 6         273 $self->once(!$self->once);
51             return undef
52 6 100       275 if $self->initial_version eq $self->to_version;
53 4         181 return [$self->initial_version, $self->to_version];
54             }
55              
56             sub previous_version_set {
57 0     0 0   my $self = shift;
58             return undef
59 0 0         if $self->once;
60              
61 0           $self->once(!$self->once);
62             return undef
63 0 0         if $self->initial_version eq $self->to_version;
64 0           return [$self->initial_version, $self->to_version];
65             }
66              
67              
68             __PACKAGE__->meta->make_immutable;
69              
70             1;
71              
72             # vim: ts=2 sw=2 expandtab
73              
74             __END__
75              
76             =pod
77              
78             =head1 NAME
79              
80             DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions - Go straight from Database to Schema version
81              
82             =head1 SEE ALSO
83              
84             This class is an implementation of
85             L<DBIx::Class::DeploymentHandler::HandlesVersioning>. Pretty much all the
86             documentation is there.
87              
88             =head1 AUTHOR
89              
90             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
91              
92             =head1 COPYRIGHT AND LICENSE
93              
94             This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
95              
96             This is free software; you can redistribute it and/or modify it under
97             the same terms as the Perl 5 programming language system itself.
98              
99             =cut