blib/lib/DBIx/Class/Schema/Loader/DBObject.pm

filter: Statementstmt 92.1% 59 / 64 Branchbran 62.5% 10 / 16 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 17 / 17 Podpod 66.6% 4 / 6 totaltotal 81.9% 95 / 116 CC 12 SCAR 11.4
CC
12
Cov
83%
dbic_name
7.3
_quote
4.9
sql_name
2.1
CRAP 3.1
« blib/lib/DBIx/Class/Schema/Loader/DBI/ODBC/SQL_Anywhere.pm ↑ Summary blib/lib/DBIx/Class/Schema/Loader/Utils.pm »
1 package DBIx::Class::Schema::Loader::DBObject;
2  
3 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 49 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 49 ▶use base 'Class::Accessor::Grouped';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 49 ▶use Carp::Clan qw/^DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 49 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 49 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 DBIx::Class::Schema::Loader::DBObject - Base Class for Database Objects Such as
14 Tables and Views in L<DBIx::Class::Schema::Loader>
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</new>.
22  
23 =head2 name
24  
25 Name of the object. The object stringifies to this value.
26  
27 =cut
28  
29 49 __PACKAGE__->mk_group_accessors(simple => qw/
30 loader
31 name
32 _schema
33 ignore_schema
34 /);
35  
36 use overload
37 17762 ▶ '""' => sub { $_[0]->name },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
38 328 ▶ '@{}' => sub { $_[0]->name_parts },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 49 fallback => 1;
40  
41 =head2 new
42  
43 The constructor, takes L</loader>, L</name>, L</schema>, and L</ignore_schema>
44 as key-value parameters.
45  
46 =cut
47  
48 2136 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
49 2136 my $class = shift;
50  
51 2136 my $self = { @_ };
52  
53 2136 ▶ croak "loader is required" unless ref $self->{loader};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"loader"} 0 2136 2136
54  
55 2136 weaken $self->{loader};
56  
57 2136 $self->{_schema} = delete $self->{schema};
58  
59 2136 return bless $self, $class;
60 }
61  
62 =head2 clone
63  
64 Make a shallow copy of the object.
65  
66 =cut
67  
68 3932 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
69 3932 my $self = shift;
70  
71 3932 return bless { %$self }, ref $self;
72 }
73  
74 =head2 schema
75  
76 The schema (or owner) of the object. Returns nothing if L</ignore_schema> is
77 true.
78  
79 =head2 ignore_schema
80  
81 Set to true to make L</schema> and L</sql_name> not use the defined L</schema>.
82 Does not affect L</dbic_name> (for
83 L<qualify_objects|DBIx::Class::Schema::Loader::Base/qualify_objects> testing on
84 SQLite.)
85  
86 =cut
87  
88 34130 ▶sub schema {
Subroutine schema: called CC=2 SCAR=6.9
Pod documented
89 34130 my $self = shift;
90  
91 34130 ▶ return $self->_schema(@_) unless $self->ignore_schema;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->ignore_schema 33272 858 34130
92  
93 858 return undef;
94 }
95  
96 25232 ▶sub _quote {
Subroutine _quote: called CC=4 SCAR=15.9
97 25232 my ($self, $identifier) = @_;
98  
99 25232 ▶ $identifier = '' if not defined $identifier;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $identifier 0 25232 25232
100  
101 25232 ▶ my $qt = $self->loader->quote_char || '';
Condition50%1/2
$self->loader->quote_char || ''
l!l
252320
MC/DC0%0/1
$self->loader->quote_char || ''
$self->loader->quote_char
Truth table50%1/2
A
A= $self->loader->quote_char
Aresult
11
00
102  
103 25232 ▶ if (length $qt > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $qt > 1) 0 25232 25232
104 0 my @qt = split //, $qt;
105 0 return $qt[0] . $identifier . $qt[1];
106 }
107  
108 25232 return "${qt}${identifier}${qt}";
109 }
110  
111 =head1 sql_name
112  
113 Returns the properly quoted full identifier with L</schema> and L</name>.
114  
115 =cut
116  
117 25232 ▶sub sql_name {
Subroutine sql_name: called CC=2 SCAR=7.4
Pod undocumented
118 25232 my $self = shift;
119  
120 25232 my $name_sep = $self->loader->name_sep;
121  
122 25232 ▶ if ($self->schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->schema) 0 25232 25232
123 0 return $self->_quote($self->schema)
124 . $name_sep
125 . $self->_quote($self->name);
126 }
127  
128 25232 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<DBIx::Class> Result files.
134  
135 =cut
136  
137 3137 ▶sub dbic_name {
Subroutine dbic_name: called CC=6 SCAR=19.9
Pod undocumented
138 3137 my $self = shift;
139  
140 3137 my $name_sep = $self->loader->name_sep;
141  
142 3137 ▶ if ($self->loader->qualify_objects && $self->_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->loader->qualify_objects and $self->_schema) 64 3073 3137
Condition66%2/3
$self->loader->qualify_objects and $self->_schema
!ll&&!rl&&r
3073064
MC/DC50%1/2
$self->loader->qualify_objects and $self->_schema
$self->loader->qualify_objects $self->_schema
Truth table66%2/3
A and B
A= $self->loader->qualify_objectsB= $self->_schema
ABresult
0X0
100
111
143 64 ▶ if ($self->_schema =~ /\W/ || $self->name =~ /\W/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_schema =~ /\W/ or $self->name =~ /\W/) 0 64 64
Condition33%1/3
$self->_schema =~ /\W/ or $self->name =~ /\W/
l!l&&r!l&&!r
0064
MC/DC0%0/2
$self->_schema =~ /\W/ or $self->name =~ /\W/
$self->_schema =~ /\W/ $self->name =~ /\W/
Truth table33%1/3
A or B
A= $self->_schema =~ /\W/B= $self->name =~ /\W/
ABresult
1X1
011
000
144 0 return \ $self->sql_name;
145 }
146  
147 64 return $self->_schema . $name_sep . $self->name;
148 }
149  
150 3073 ▶ if ($self->name =~ /\W/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->name =~ /\W/) 0 3073 3073
151 0 return \ $self->_quote($self->name);
152 }
153  
154 3073 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<moniker_parts|DBIx::Class::Schema::Loader::Base/moniker_parts> of
161 the L</loader> object. The object arrayrefifies to this value.
162  
163 =cut
164  
165 1327 ▶sub name_parts {
Subroutine name_parts: called CC=1 SCAR=0.0
Pod documented
166 1327 my ($self) = shift;
167 1327 return [ map { $self->$_ } @{$self->loader->moniker_parts} ];
168 }
169  
170  
171 =head1 SEE ALSO
172  
173 L<DBIx::Class::Schema::Loader::Table>, L<DBIx::Class::Schema::Loader>,
174 L<DBIx::Class::Schema::Loader::Base>
175  
176 =head1 AUTHORS
177  
178 See L<DBIx::Class::Schema::Loader/AUTHORS>.
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 49 1;
188 # vim:et sts=4 sw=4 tw=0:
« blib/lib/DBIx/Class/Schema/Loader/DBI/ODBC/SQL_Anywhere.pm ↑ Summary blib/lib/DBIx/Class/Schema/Loader/Utils.pm »