File Coverage

blib/lib/DBIx/Class/Schema/Loader/DBObject.pm
Criterion Covered Total %
statement 58 62 93.5
branch 11 16 68.7
condition 4 8 50.0
subroutine 17 17 100.0
pod 4 6 66.6
total 94 109 86.2


line stmt bran cond sub pod time code
1             package DBIx::Class::Schema::Loader::DBObject;
2              
3 17     17   151 use strict;
  17         46  
  17         507  
4 17     17   101 use warnings;
  17         44  
  17         419  
5 17     17   94 use base 'Class::Accessor::Grouped';
  17         41  
  17         1875  
6 17     17   175 use mro 'c3';
  17         49  
  17         100  
7 17     17   604 use Carp::Clan qw/^DBIx::Class/;
  17         57  
  17         117  
8 17     17   2007 use Scalar::Util 'weaken';
  17         58  
  17         1008  
9 17     17   151 use namespace::clean;
  17         53  
  17         109  
10              
11             =head1 NAME
12              
13             DBIx::Class::Schema::Loader::DBObject - Base Class for Database Objects Such as
14             Tables and Views in L
15              
16             =head1 METHODS
17              
18             =head2 loader
19              
20             The loader object this object is associated with, this is a required parameter
21             to L.
22              
23             =head2 name
24              
25             Name of the object. The object stringifies to this value.
26              
27             =cut
28              
29             __PACKAGE__->mk_group_accessors(simple => qw/
30             loader
31             name
32             _schema
33             ignore_schema
34             /);
35              
36             use overload
37 19921     19921   1206545 '""' => sub { $_[0]->name },
38 321     321   1178 '@{}' => sub { $_[0]->name_parts },
39 17     17   6212 fallback => 1;
  17         59  
  17         263  
40              
41             =head2 new
42              
43             The constructor, takes L, L, L, and L
44             as key-value parameters.
45              
46             =cut
47              
48             sub new {
49 2010     2010 1 5017 my $class = shift;
50              
51 2010         8645 my $self = { @_ };
52              
53 2010 50       7120 croak "loader is required" unless ref $self->{loader};
54              
55 2010         7576 weaken $self->{loader};
56              
57 2010         5152 $self->{_schema} = delete $self->{schema};
58              
59 2010         25697 return bless $self, $class;
60             }
61              
62             =head2 clone
63              
64             Make a shallow copy of the object.
65              
66             =cut
67              
68             sub clone {
69 3736     3736 1 9374 my $self = shift;
70              
71 3736         34067 return bless { %$self }, ref $self;
72             }
73              
74             =head2 schema
75              
76             The schema (or owner) of the object. Returns nothing if L is
77             true.
78              
79             =head2 ignore_schema
80              
81             Set to true to make L and L not use the defined L.
82             Does not affect L (for
83             L testing on
84             SQLite.)
85              
86             =cut
87              
88             sub schema {
89 32657     32657 1 292918 my $self = shift;
90              
91 32657 100       150133 return $self->_schema(@_) unless $self->ignore_schema;
92              
93 429         1593 return undef;
94             }
95              
96             sub _quote {
97 24197     24197   55277 my ($self, $identifier) = @_;
98              
99 24197 50       51397 $identifier = '' if not defined $identifier;
100              
101 24197   50     71345 my $qt = $self->loader->quote_char || '';
102              
103 24197 50       56275 if (length $qt > 1) {
104 0         0 my @qt = split //, $qt;
105 0         0 return $qt[0] . $identifier . $qt[1];
106             }
107              
108 24197         140687 return "${qt}${identifier}${qt}";
109             }
110              
111             =head1 sql_name
112              
113             Returns the properly quoted full identifier with L and L.
114              
115             =cut
116              
117             sub sql_name {
118 23843     23843 0 1272243 my $self = shift;
119              
120 23843         70285 my $name_sep = $self->loader->name_sep;
121              
122 23843 100       55417 if ($self->schema) {
123 354         794 return $self->_quote($self->schema)
124             . $name_sep
125             . $self->_quote($self->name);
126             }
127              
128 23489         71020 return $self->_quote($self->name);
129             }
130              
131             =head1 dbic_name
132              
133             Returns a value suitable for the C<< __PACKAGE__->table >> call in L Result files.
134              
135             =cut
136              
137             sub dbic_name {
138 2979     2979 0 6868 my $self = shift;
139              
140 2979         10819 my $name_sep = $self->loader->name_sep;
141              
142 2979 100 66     13486 if ($self->loader->qualify_objects && $self->_schema) {
143 32 50 33     287 if ($self->_schema =~ /\W/ || $self->name =~ /\W/) {
144 0         0 return \ $self->sql_name;
145             }
146              
147 32         365 return $self->_schema . $name_sep . $self->name;
148             }
149              
150 2947 50       16840 if ($self->name =~ /\W/) {
151 0         0 return \ $self->_quote($self->name);
152             }
153              
154 2947         19731 return $self->name;
155             }
156              
157             =head2 name_parts
158              
159             Returns an arrayref of the values returned by the methods specified in
160             the L of
161             the L object. The object arrayrefifies to this value.
162              
163             =cut
164              
165             sub name_parts {
166 1320     1320 1 3429 my ($self) = shift;
167 1320         2578 return [ map { $self->$_ } @{$self->loader->moniker_parts} ];
  1327         10012  
  1320         5296  
168             }
169              
170              
171             =head1 SEE ALSO
172              
173             L, L,
174             L
175              
176             =head1 AUTHORS
177              
178             See L.
179              
180             =head1 LICENSE
181              
182             This library is free software; you can redistribute it and/or modify it under
183             the same terms as Perl itself.
184              
185             =cut
186              
187             1;
188             # vim:et sts=4 sw=4 tw=0: