DeploymentHandler/VersionHandler/Monotonic.pm

filter: Statementstmt 100% 40 / 40 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 92.7% 64 / 69 CC 8 SCAR 7.8
CC
8
Cov
96%
__ANON__
3.0
previous_version_set
3.0
next_version_set
3.0
CRAP 2.2
« DeploymentHandler/VersionHandler/ExplicitVersions.pm ↑ Summary DeploymentHandler/Dad.pm »
1 package DBIx::Class::DeploymentHandler::VersionHandler::Monotonic;
2 12 $DBIx::Class::DeploymentHandler::VersionHandler::Monotonic::VERSION = '0.002233';
3 12 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use DBIx::Class::DeploymentHandler::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Obvious version progressions
7  
8 12 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
11  
12 12 has schema_version => (
13 isa => 'DBIx::Class::DeploymentHandler::VersionNonObj',
14 coerce => 1,
15 is => 'ro',
16 required => 1,
17 );
18  
19 12 has initial_version => (
20 isa => 'Int',
21 is => 'ro',
22 required => 1,
23 );
24  
25 12 has to_version => (
26 isa => 'DBIx::Class::DeploymentHandler::VersionNonObj',
27 coerce => 1,
28 is => 'ro',
29 lazy_build => 1,
30 );
31  
32 sub _build_to_version {
33 1 ▶ my $version = $_[0]->schema_version;
Subroutine _build_to_version: called CC=2 SCAR=7.2
34 1 ▶ ref($version) ? $version->numify : $version;
Branch: 1 branch
BranchTrueFalseTotal
ref $version ? : 0 1 1
35 }
36  
37 12 has _version => (
38 is => 'rw',
39 isa => 'Int',
40 lazy_build => 1,
41 );
42  
43 18 ▶sub _inc_version { $_[0]->_version($_[0]->_version + 1 ) }
Subroutine _inc_version: called CC=1 SCAR=0.0
44 11 ▶sub _dec_version { $_[0]->_version($_[0]->_version - 1 ) }
Subroutine _dec_version: called CC=1 SCAR=0.0
45  
46 25 ▶sub _build__version { $_[0]->initial_version }
Subroutine _build__version: called CC=1 SCAR=0.0
47  
48 # provide backwards compatibility for initial_version/database_version
49 around BUILDARGS => sub {
50 28 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
51 28 my $class = shift;
52  
53 28 my $args = $class->$orig(@_);
54 $args->{initial_version} = $args->{database_version}
55 28 ▶ if exists $args->{database_version} && !exists $args->{initial_version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"database_version"} and not exists $args->{"initial_version"} 8 20 28
Condition66%2/3
exists $args->{"database_version"} and not exists $args->{"initial_version"}
!ll&&!rl&&r
2008
MC/DC50%1/2
exists $args->{"database_version"} and not exists $args->{"initial_version"}
exists $args->{"database_version"} not exists $args->{"initial_version"}
Truth table66%2/3
A and not(B)
A= exists $args->{"database_version"}B= not exists $args->{"initial_version"}
ABresult
0X0
100
111
56 28 return $args;
57 12 };
58  
59 sub previous_version_set {
60 21 ▶ my $self = shift;
Subroutine previous_version_set: called CC=3 SCAR=11.0
Pod undocumented
61 21 ▶ if ($self->to_version > $self->_version) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->to_version > $self->_version) { } 1 20 21
elsif ($self->to_version == $self->_version) { } 9 11 20
62 1 croak "you are trying to downgrade and your current version is less\n".
63 "than the version you are trying to downgrade to. Either upgrade\n".
64 "or update your schema"
65 } elsif ( $self->to_version == $self->_version) {
66 return undef
67 9 } else {
68 11 $self->_dec_version;
69 11 return [$self->_version + 1, $self->_version];
70 }
71 }
72  
73 sub next_version_set {
74 36 ▶ my $self = shift;
Subroutine next_version_set: called CC=3 SCAR=11.0
Pod undocumented
75 36 ▶ if ($self->to_version < $self->initial_version) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->to_version < $self->initial_version) { } 1 35 36
elsif ($self->to_version == $self->_version) { } 17 18 35
76 1 croak "you are trying to upgrade and your current version is greater\n".
77 "than the version you are trying to upgrade to. Either downgrade\n".
78 "or update your schema"
79 } elsif ( $self->to_version == $self->_version) {
80 return undef
81 17 } else {
82 18 $self->_inc_version;
83 18 return [$self->_version - 1, $self->_version];
84 }
85 }
86  
87 12 __PACKAGE__->meta->make_immutable;
88  
89 12 1;
90  
91 # vim: ts=2 sw=2 expandtab
92  
93 __END__
94  
95 =pod
96  
97 =head1 NAME
98  
99 DBIx::Class::DeploymentHandler::VersionHandler::Monotonic - Obvious version progressions
100  
101 =head1 SEE ALSO
102  
103 This class is an implementation of
104 L<DBIx::Class::DeploymentHandler::HandlesVersioning>. Pretty much all the
105 documentation is there.
106  
107 =head1 AUTHOR
108  
109 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
110  
111 =head1 COPYRIGHT AND LICENSE
112  
113 This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
114  
115 This is free software; you can redistribute it and/or modify it under
116 the same terms as the Perl 5 programming language system itself.
117  
118 =cut
« DeploymentHandler/VersionHandler/ExplicitVersions.pm ↑ Summary DeploymentHandler/Dad.pm »