File Coverage

lib/DBIx/Schema/Changelog/Action/Default.pm
Criterion Covered Total %
statement 35 35 100.0
branch 9 12 75.0
condition n/a
subroutine 11 11 100.0
pod 3 3 100.0
total 58 61 95.0


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