X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FComponent%2FQuotedDefault.pm;h=772dbb24b252fab86f761a99986834a220c5b271;hb=afa71a988919e114101e41f0241b08ffc2f436f5;hp=97a94cea8565ea8a8e14d39bc104c607dcac0e34;hpb=6b0e47fc86f045183810ccea343e9afcd438ee1a;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm index 97a94ce..772dbb2 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm @@ -2,14 +2,15 @@ package DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault; use strict; use warnings; -use Class::C3; +use base 'DBIx::Class::Schema::Loader::DBI'; +use mro 'c3'; -our $VERSION = '0.05000'; +our $VERSION = '0.07048_01'; =head1 NAME -DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault -- Loader Component -to parse quoted default constants and functions +DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault -- Loader::DBI +Component to parse quoted default constants and functions =head1 DESCRIPTION @@ -23,23 +24,35 @@ sub _columns_info_for { my $self = shift; my ($table) = @_; - my $result = $self->next::method(@_); + my ($result,$raw) = $self->next::method(@_); while (my ($col, $info) = each %$result) { if (my $def = $info->{default_value}) { $def =~ s/^\s+//; $def =~ s/\s+\z//; - if ($def =~ /^["'](.*?)['"]\z/) { +# remove Pg typecasts (e.g. 'foo'::character varying) too + if ($def =~ /^["'](.*?)['"](?:::[\w\s]+)?\z/) { $info->{default_value} = $1; } +# Some DBs (eg. Pg) put parenthesis around negative number defaults + elsif ($def =~ /^\((-?\d.*?)\)(?:::[\w\s]+)?\z/) { + $info->{default_value} = $1; + } + elsif ($def =~ /^(-?\d.*?)(?:::[\w\s]+)?\z/) { + $info->{default_value} = $1; + } + elsif ($def =~ /^NULL:?/i) { + my $null = 'null'; + $info->{default_value} = \$null; + } else { - $info->{default_value} = $def =~ /^\d/ ? $def : \$def; + $info->{default_value} = \$def; } } } - return $result; + return wantarray ? ($result, $raw) : $result; } 1; @@ -49,9 +62,9 @@ sub _columns_info_for { L, L, L -=head1 AUTHOR +=head1 AUTHORS -See L and L. +See L. =head1 LICENSE