• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.9.5/CPANInternal-140/DBIx-Class-Schema-Loader-0.05003/lib/DBIx/Class/Schema/Loader/DBI/Component/
1package DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault;
2
3use strict;
4use warnings;
5use Class::C3;
6
7our $VERSION = '0.05003';
8
9=head1 NAME
10
11DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault -- Loader::DBI
12Component to parse quoted default constants and functions
13
14=head1 DESCRIPTION
15
16If C<COLUMN_DEF> from L<DBI/column_info> returns character constants quoted,
17then we need to remove the quotes. This also allows distinguishing between
18default functions without information schema introspection.
19
20=cut
21
22sub _columns_info_for {
23    my $self    = shift;
24    my ($table) = @_;
25
26    my $result = $self->next::method(@_);
27
28    while (my ($col, $info) = each %$result) {
29        if (my $def = $info->{default_value}) {
30            $def =~ s/^\s+//;
31            $def =~ s/\s+\z//;
32
33# remove Pg typecasts (e.g. 'foo'::character varying) too
34            if ($def =~ /^["'](.*?)['"](?:::[\w\s]+)?\z/) {
35                $info->{default_value} = $1;
36            }
37            else {
38                $info->{default_value} = $def =~ /^\d/ ? $def : \$def;
39            }
40        }
41    }
42
43    return $result;
44}
45
461;
47
48=head1 SEE ALSO
49
50L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
51L<DBIx::Class::Schema::Loader::DBI>
52
53=head1 AUTHOR
54
55See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
56
57=head1 LICENSE
58
59This library is free software; you can redistribute it and/or modify it under
60the same terms as Perl itself.
61
62=cut
63