File Coverage

lib/DBIx/Schema/Changelog/Action/Entry.pm
Criterion Covered Total %
statement 31 46 67.3
branch n/a
condition n/a
subroutine 8 10 80.0
pod 3 3 100.0
total 42 59 71.1


line stmt bran cond sub pod time code
1             package DBIx::Schema::Changelog::Action::Entry;
2              
3             =head1 NAME
4              
5             DBIx::Schema::Changelog::Action::Sql - Action to insert change or delete entries from tables
6              
7             =head1 VERSION
8              
9             Version 0.7.2
10              
11             =cut
12              
13             our $VERSION = '0.7.2';
14              
15 5     5   2508 use utf8;
  5         39  
  5         24  
16 5     5   155 use strict;
  5         8  
  5         154  
17 5     5   17 use warnings;
  5         7  
  5         147  
18 5     5   18 use Moose;
  5         6  
  5         35  
19 5     5   28788 use SQL::Abstract;
  5         42193  
  5         352  
20 5     5   47 use Data::Dumper;
  5         6  
  5         1786  
21              
22             with 'DBIx::Schema::Changelog::Action';
23              
24             has sql_abstract => (
25             is => 'ro',
26             lazy => 1,
27             isa => 'SQL::Abstract',
28             default => sub { SQL::Abstract->new( array_datatypes => 1 ) },
29             );
30              
31             =head1 SUBROUTINES/METHODS
32              
33             =over 4
34              
35             =item add
36              
37             Insert entry into table
38              
39             =cut
40              
41             sub add {
42 1     1 1 4 my ( $self, $params ) = @_;
43 1         3 my $qmarks = [];
44 1         1 push( @$qmarks, '?' ) foreach ( @{ $params->{cols} } );
  1         10  
45 1         12 my $stmt =
46             'INSERT INTO '
47             . $params->{name} . ' ( '
48 1         5 . join( ',', @{ $params->{cols} } )
49             . ') VALUES ('
50             . join( ',', @$qmarks ) . ')';
51 1         47 my $pp = $self->dbh()->prepare($stmt);
52 1         147 $pp->execute(@$_) foreach ( @{ $params->{add} } );
  1         57620  
53 1         44 return $stmt;
54             }
55              
56             =item alter
57              
58             Change values from entry in table
59              
60             =cut
61              
62             sub alter {
63 0     0 1   my ( $self, $params ) = @_;
64 0           my %data = map { $_ => 1 } @{ $params->{cols} };
  0            
  0            
65 0           my ( $stmt, @bind ) =
66             $self->sql_abstract()
67             ->update( $params->{name}, \%data, $params->{where} );
68 0           my $pp = $self->dbh()->prepare($stmt);
69 0           $pp->execute(@$_) foreach @{ $params->{alter} };
  0            
70 0           return $stmt;
71             }
72              
73             =item drop
74              
75             Delete entry from table
76              
77             =cut
78              
79             sub drop {
80 0     0 1   my ( $self, $params ) = @_;
81 0           my ( $stmt, @bind ) =
82             $self->sql_abstract()->delete( $params->{name}, $params->{where} );
83 0           my $pp = $self->dbh()->prepare($stmt);
84 0           $pp->execute(@$_) foreach @{ $params->{delete} };
  0            
85 0           return $stmt;
86             }
87              
88 5     5   30 no Moose;
  5         7  
  5         45  
89             __PACKAGE__->meta->make_immutable;
90              
91             1;
92              
93             __END__
94              
95             =back
96              
97             =head1 AUTHOR
98              
99             Mario Zieschang, C<< <mario.zieschang at combase.de> >>
100              
101             =head1 LICENSE AND COPYRIGHT
102              
103             Copyright 2015 Mario Zieschang.
104              
105             This program is free software; you can redistribute it and/or modify it
106             under the terms of the the Artistic License (2.0). You may obtain a
107             copy of the full license at:
108              
109             L<http://www.perlfoundation.org/artistic_license_2_0>
110              
111             Any use, modification, and distribution of the Standard or Modified
112             Versions is governed by this Artistic License. By using, modifying or
113             distributing the Package, you accept this license. Do not use, modify,
114             or distribute the Package, if you do not accept this license.
115              
116             If your Modified Version has been derived from a Modified Version made
117             by someone other than you, you are nevertheless required to ensure that
118             your Modified Version complies with the requirements of this license.
119              
120             This license does not grant you the right to use any trademark, service
121             mark, trade name, or logo of the Copyright Holder.
122              
123             This license includes the non-exclusive, worldwide, free-of-charge
124             patent license to make, have made, use, offer to sell, sell, import and
125             otherwise transfer the Package with respect to any patent claims
126             licensable by the Copyright Holder that are necessarily infringed by the
127             Package. If you institute patent litigation (including a cross-claim or
128             counterclaim) against any party alleging that the Package constitutes
129             direct or contributory patent infringement, then this Artistic License
130             to you shall terminate on the date that such litigation is filed.
131              
132             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
133             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
134             THE IMPLIED WARRANTIES OF MERCHANT ABILITY, FITNESS FOR A PARTICULAR
135             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
136             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
137             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
138             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
139             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
140              
141             =cut