File Coverage

lib/DBIx/Schema/Changelog/Changeset.pm
Criterion Covered Total %
statement 58 58 100.0
branch 30 46 65.2
condition n/a
subroutine 12 12 100.0
pod 1 1 100.0
total 101 117 86.3


line stmt bran cond sub pod time code
1             package DBIx::Schema::Changelog::Changeset;
2              
3             =head1 NAME
4              
5             DBIx::Schema::Changelog::Changeset - Handles action types.
6              
7             =head1 VERSION
8              
9             Version 0.8.0
10              
11             =cut
12              
13             our $VERSION = '0.8.0';
14              
15 5     5   1178 use utf8;
  5         21  
  5         35  
16 5     5   226 use strict;
  5         15  
  5         433  
17 5     5   35 use warnings;
  5         11  
  5         237  
18 5     5   7847 use Moose;
  5         3887691  
  5         145  
19 5     5   52886 use Method::Signatures::Simple;
  5         86541  
  5         50  
20 5     5   6777 use MooseX::HasDefaults::RO;
  5         92335  
  5         42  
21 5     5   82681 use DBIx::Schema::Changelog::Action::Sql;
  5         29  
  5         462  
22 5     5   4690 use DBIx::Schema::Changelog::Action::Function;
  5         19  
  5         268  
23 5     5   4329 use DBIx::Schema::Changelog::Action::Entry;
  5         22  
  5         292  
24 5     5   56 use Data::Dumper;
  5         10  
  5         947  
25              
26             has driver => ();
27             has dbh => ();
28             has table_action => ( isa => 'DBIx::Schema::Changelog::Action::Table', );
29              
30             has sql_action => (
31             lazy => 1,
32             does => 'DBIx::Schema::Changelog::Action',
33             default => method {
34             DBIx::Schema::Changelog::Action::Sql->new(
35             driver => $self->driver(),
36             dbh => $self->dbh()
37             )
38             },
39             );
40              
41             has seq_action => (
42             is => 'rw',
43             lazy => 1,
44             does => 'DBIx::Schema::Changelog::Action',
45             default => method {
46             DBIx::Schema::Changelog::Action::Sequence->new(
47             driver => $self->driver(),
48             dbh => $self->dbh()
49             )
50             },
51             );
52              
53             has index_action => (
54             lazy => 1,
55             does => 'DBIx::Schema::Changelog::Action',
56             default => method {
57             DBIx::Schema::Changelog::Action::Index->new(
58             driver => $self->driver(),
59             dbh => $self->dbh()
60             )
61             },
62             );
63              
64             has view_action => (
65             lazy => 1,
66             does => 'DBIx::Schema::Changelog::Action',
67             default => method {
68             DBIx::Schema::Changelog::Action::View->new(
69             driver => $self->driver(),
70             dbh => $self->dbh()
71             )
72             },
73             );
74              
75             has trigger_action => (
76             lazy => 1,
77             does => 'DBIx::Schema::Changelog::Action',
78             default => method {
79             DBIx::Schema::Changelog::Action::Trigger->new(
80             driver => $self->driver(),
81             dbh => $self->dbh()
82             )
83             },
84             );
85              
86             has funct_action => (
87             lazy => 1,
88             does => 'DBIx::Schema::Changelog::Action',
89             default => method {
90             DBIx::Schema::Changelog::Action::Function->new(
91             driver => $self->driver(),
92             dbh => $self->dbh()
93             )
94             },
95             );
96              
97 14     14 1 33 has entry_action => (
98 14         46 lazy => 1,
99 24 50       104 does => 'DBIx::Schema::Changelog::Action',
100             default => method {
101             DBIx::Schema::Changelog::Action::Entry->new(
102 24 100       1581 driver => $self->driver(),
103 24 100       2068046 dbh => $self->dbh()
104 24 100       204941 )
105             },
106             );
107 24 100       185214  
108 24 50       108 =head1 SUBROUTINES/METHODS
109 24 50       88  
110             =over 4
111              
112 24 100       114 =item handle
113 24 50       198383  
114 24 50       88 Handles different changeset commands
115              
116             =cut
117 24 50       87  
118 24 50       85 sub handle {
119 24 50       94 my ( $self, $entries ) = @_;
120             foreach (@$entries) {
121             die "No type set for changeset" . Dumper($_) unless $_->{type};
122 24 50       281  
123 24 50       85 # table actions
124 24 50       76 $self->table_action()->add($_) if ( $_->{type} eq 'createtable' );
125             $self->table_action()->drop($_) if ( $_->{type} eq 'droptable' );
126             $self->table_action()->alter($_) if ( $_->{type} eq 'altertable' );
127 24 50       84  
128 24 50       90 # index actions
129 24 50       150 $self->index_action()->add($_) if ( $_->{type} eq 'createindex' );
130             $self->index_action()->alter($_) if ( $_->{type} eq 'alterindex' );
131             $self->index_action()->drop($_) if ( $_->{type} eq 'dropindex' );
132 24 100       157  
133             # view actions
134             $self->view_action()->add($_) if ( $_->{type} eq 'createview' );
135 24 100       646 $self->view_action()->alter($_) if ( $_->{type} eq 'alterview' );
136 24 50       100 $self->view_action()->drop($_) if ( $_->{type} eq 'dropview' );
137 24 50       210  
138             # sequence actions
139             $self->seq_action()->add($_) if ( $_->{type} eq 'createsequence' );
140             $self->seq_action()->alter($_) if ( $_->{type} eq 'altersequence' );
141 5     5   18050 $self->seq_action()->drop($_) if ( $_->{type} eq 'dropsequence' );
  5         16  
  5         66  
142              
143             # function actions
144             $self->funct_action()->add($_) if ( $_->{type} eq 'createfunction' );
145             $self->funct_action()->alter($_) if ( $_->{type} eq 'alterfunction' );
146             $self->funct_action()->drop($_) if ( $_->{type} eq 'dropfunction' );
147              
148             # function actions
149             $self->trigger_action()->add($_) if ( $_->{type} eq 'createtrigger' );
150             $self->trigger_action()->alter($_) if ( $_->{type} eq 'altertrigger' );
151             $self->trigger_action()->drop($_) if ( $_->{type} eq 'droptrigger' );
152              
153             # manually called sql statement
154             $self->sql_action()->add($_) if ( $_->{type} eq 'sql' );
155              
156             # entry statements
157             $self->entry_action()->add($_) if ( $_->{type} eq 'insert' );
158             $self->entry_action()->add($_) if ( $_->{type} eq 'set' );
159             $self->entry_action()->add($_) if ( $_->{type} eq 'delete' );
160             }
161             }
162              
163             no Moose;
164             __PACKAGE__->meta->make_immutable;
165              
166             1; # End of DBIx::Schema::Changelog::Changeset
167              
168             __END__
169              
170             =back
171              
172             =head1 AUTHOR
173              
174             Mario Zieschang, C<< <mario.zieschang at combase.de> >>
175              
176             =head1 LICENSE AND COPYRIGHT
177              
178             Copyright 2015 Mario Zieschang.
179              
180             This program is free software; you can redistribute it and/or modify it
181             under the terms of the the Artistic License (2.0). You may obtain a
182             copy of the full license at:
183              
184             L<http://www.perlfoundation.org/artistic_license_2_0>
185              
186             Any use, modification, and distribution of the Standard or Modified
187             Versions is governed by this Artistic License. By using, modifying or
188             distributing the Package, you accept this license. Do not use, modify,
189             or distribute the Package, if you do not accept this license.
190              
191             If your Modified Version has been derived from a Modified Version made
192             by someone other than you, you are nevertheless required to ensure that
193             your Modified Version complies with the requirements of this license.
194              
195             This license does not grant you the right to use any trademark, service
196             mark, trade name, or logo of the Copyright Holder.
197              
198             This license includes the non-exclusive, worldwide, free-of-charge
199             patent license to make, have made, use, offer to sell, sell, import and
200             otherwise transfer the Package with respect to any patent claims
201             licensable by the Copyright Holder that are necessarily infringed by the
202             Package. If you institute patent litigation (including a cross-claim or
203             counterclaim) against any party alleging that the Package constitutes
204             direct or contributory patent infringement, then this Artistic License
205             to you shall terminate on the date that such litigation is filed.
206              
207             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
208             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
209             THE IMPLIED WARRANTIES OF MERCHANT ABILITY, FITNESS FOR A PARTICULAR
210             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
211             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
212             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
213             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
214             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
215              
216             =cut