1package DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault; 2 3use strict; 4use warnings; 5use base 'DBIx::Class::Schema::Loader::DBI'; 6use mro 'c3'; 7 8our $VERSION = '0.07033'; 9 10=head1 NAME 11 12DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault -- Loader::DBI 13Component to parse quoted default constants and functions 14 15=head1 DESCRIPTION 16 17If C<COLUMN_DEF> from L<DBI/column_info> returns character constants quoted, 18then we need to remove the quotes. This also allows distinguishing between 19default functions without information schema introspection. 20 21=cut 22 23sub _columns_info_for { 24 my $self = shift; 25 my ($table) = @_; 26 27 my $result = $self->next::method(@_); 28 29 while (my ($col, $info) = each %$result) { 30 if (my $def = $info->{default_value}) { 31 $def =~ s/^\s+//; 32 $def =~ s/\s+\z//; 33 34# remove Pg typecasts (e.g. 'foo'::character varying) too 35 if ($def =~ /^["'](.*?)['"](?:::[\w\s]+)?\z/) { 36 $info->{default_value} = $1; 37 } 38# Some DBs (eg. Pg) put parenthesis around negative number defaults 39 elsif ($def =~ /^\((-?\d.*?)\)(?:::[\w\s]+)?\z/) { 40 $info->{default_value} = $1; 41 } 42 elsif ($def =~ /^(-?\d.*?)(?:::[\w\s]+)?\z/) { 43 $info->{default_value} = $1; 44 } 45 elsif ($def =~ /^NULL:?/i) { 46 my $null = 'null'; 47 $info->{default_value} = \$null; 48 } 49 else { 50 $info->{default_value} = \$def; 51 } 52 } 53 } 54 55 return $result; 56} 57 581; 59 60=head1 SEE ALSO 61 62L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>, 63L<DBIx::Class::Schema::Loader::DBI> 64 65=head1 AUTHOR 66 67See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>. 68 69=head1 LICENSE 70 71This library is free software; you can redistribute it and/or modify it under 72the same terms as Perl itself. 73 74=cut 75