multi db_schema support
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBObject / Informix.pm
1 package DBIx::Class::Schema::Loader::DBObject::Informix;
2
3 use strict;
4 use warnings;
5 use base 'DBIx::Class::Schema::Loader::DBObject';
6 use namespace::clean;
7
8 =head1 NAME
9
10 DBIx::Class::Schema::Loader::DBObject::Informix - Class for Database Objects for
11 Informix Such as Tables and Views in L<DBIx::Class::Schema::Loader>
12
13 =head1 DESCRIPTION
14
15 This is a subclass of L<DBIx::Class::Schema::Loader::DBObject> that adds
16 support for fully qualified objects in Informix including both L</database>
17 and L<schema|DBIx::Class::Schema::Loader::DBObject/schema> of the form:
18
19     database:owner.object_name
20
21 =head1 METHODS
22
23 =head2 database
24
25 The database name this object belongs to.
26
27 Returns undef if
28 L<ignore_schema|DBIx::Class::Schema::Loader::DBObject/ignore_schema> is set.
29
30 =cut
31
32 __PACKAGE__->mk_group_accessors(simple => qw/
33     _database
34 /);
35
36 sub new {
37     my $class = shift;
38
39     my $self = $class->next::method(@_);
40
41     $self->{_database} = delete $self->{database};
42
43     return $self;
44 }
45
46 sub database {
47     my $self = shift;
48
49     return $self->_database(@_) unless $self->ignore_schema;
50
51     return undef;
52 }
53
54 =head1 sql_name
55
56 Returns the properly quoted full identifier with L</database>,
57 L<schema|DBIx::Class::Schema::Loader::DBObject/schema> and
58 L<name|DBIx::Class::Schema::Loader::DBObject/name>.
59
60 =cut
61
62 sub sql_name {
63     my $self = shift;
64
65     my $name_sep = $self->loader->name_sep;
66
67     if ($self->database) {
68         return $self->_quote($self->database)
69             . ':'
70             . $self->_quote($self->schema)
71             . $name_sep
72             . $self->_quote($self->name);
73     }
74
75     return $self->next::method(@_);
76 }
77
78 sub dbic_name {
79     my $self = shift;
80
81     my $name_sep = $self->loader->name_sep;
82
83     if ($self->loader->qualify_objects && $self->_database) {
84         if ($self->_database =~ /\W/
85             || $self->_schema =~ /\W/ || $self->name =~ /\W/) {
86
87             return \ $self->sql_name;
88         }
89
90         return $self->_database . ':' . $self->_schema . $name_sep . $self->name;
91     }
92
93     return $self->next::method(@_);
94 }
95
96 =head1 SEE ALSO
97
98 L<DBIx::Class::Schema::Loader::Table::Informix>,
99 L<DBIx::Class::Schema::Loader::DBObject>,
100 L<DBIx::Class::Schema::Loader::Table>, L<DBIx::Class::Schema::Loader>,
101 L<DBIx::Class::Schema::Loader::Base>
102
103 =head1 AUTHOR
104
105 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
106
107 =head1 LICENSE
108
109 This library is free software; you can redistribute it and/or modify it under
110 the same terms as Perl itself.
111
112 =cut
113
114 1;
115 # vim:et sts=4 sw=4 tw=0: