File Coverage

lib/DBIx/Schema/Changelog/Action/Default.pm
Criterion Covered Total %
statement 32 32 100.0
branch 9 12 75.0
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 54 57 94.7


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