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 50     50   447 use strict;
  50         123  
  50         2059  
4 50     50   322 use warnings;
  50         122  
  50         2959  
5 50     50   350 use base 'Class::Accessor::Grouped';
  50         111  
  50         7184  
6 50     50   380 use mro 'c3';
  50         182  
  50         347  
7 50     50   2107 use Carp::Clan qw/^DBIx::Class/;
  50         119  
  50         420  
8 50     50   6438 use Scalar::Util 'weaken';
  50         143  
  50         3517  
9 50     50   371 use namespace::clean;
  50         117  
  50         480  
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 21429     21429   1581993 '""' => sub { $_[0]->name },
38 328     328   1598 '@{}' => sub { $_[0]->name_parts },
39 50     50   20971 fallback => 1;
  50         304  
  50         902  
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 2172     2172 1 6297 my $class = shift;
50              
51 2172         11351 my $self = { @_ };
52              
53 2172 50       8033 croak "loader is required" unless ref $self->{loader};
54              
55 2172         6076 weaken $self->{loader};
56              
57 2172         6253 $self->{_schema} = delete $self->{schema};
58              
59 2172         33013 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 4055     4055 1 12115 my $self = shift;
70              
71 4055         48625 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 35495     35495 1 375024 my $self = shift;
90              
91 35495 100       225222 return $self->_schema(@_) unless $self->ignore_schema;
92              
93 858         5036 return undef;
94             }
95              
96             sub _quote {
97 26282     26282   78972 my ($self, $identifier) = @_;
98              
99 26282 50       61727 $identifier = '' if not defined $identifier;
100              
101 26282   50     96393 my $qt = $self->loader->quote_char || '';
102              
103 26282 50       65684 if (length $qt > 1) {
104 0         0 my @qt = split //, $qt;
105 0         0 return $qt[0] . $identifier . $qt[1];
106             }
107              
108 26282         176480 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 25928     25928 0 2687971 my $self = shift;
119              
120 25928         106009 my $name_sep = $self->loader->name_sep;
121              
122 25928 100       84685 if ($self->schema) {
123 354         959 return $self->_quote($self->schema)
124             . $name_sep
125             . $self->_quote($self->name);
126             }
127              
128 25574         103999 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 3236     3236 0 8297 my $self = shift;
139              
140 3236         18849 my $name_sep = $self->loader->name_sep;
141              
142 3236 100 66     20962 if ($self->loader->qualify_objects && $self->_schema) {
143 64 50 33     2222 if ($self->_schema =~ /\W/ || $self->name =~ /\W/) {
144 0         0 return \ $self->sql_name;
145             }
146              
147 64         875 return $self->_schema . $name_sep . $self->name;
148             }
149              
150 3172 50       35314 if ($self->name =~ /\W/) {
151 0         0 return \ $self->_quote($self->name);
152             }
153              
154 3172         31025 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 1327     1327 1 5100 my ($self) = shift;
167 1327         3546 return [ map { $self->$_ } @{$self->loader->moniker_parts} ];
  1341         13136  
  1327         7586  
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: