File Coverage

lib/DBIx/Schema/Changelog/Changeset.pm
Criterion Covered Total %
statement 55 55 100.0
branch 30 46 65.2
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 97 113 85.8


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