File Coverage

lib/DBIx/Schema/Changelog/Action/Function.pm
Criterion Covered Total %
statement 15 36 41.6
branch 0 18 0.0
condition 0 6 0.0
subroutine 5 8 62.5
pod 3 3 100.0
total 23 71 32.3


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