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