SearchBuilder/Record.pm

filter: Statementstmt 89.7% 366 / 408 Branchbran 72.0% 124 / 172 Conditioncond 52.8% 56 / 106 MC/DCmcdc 30.3% 17 / 56 Subroutinesub 98.1% 54 / 55 Podpod 94.1% 16 / 17 totaltotal 77.7% 633 / 814 CC 134 SCAR 28.6
CC
134
Cov
80%
__Set
52.7
Create
52.4
LoadByCols
15.4
CRAP 17.4
« SearchBuilder/Handle/Oracle.pm ↑ Summary SearchBuilder/SchemaGenerator.pm »
1 package DBIx::SearchBuilder::Record;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Class::ReturnValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use Encode qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 21 ▶use DBIx::SearchBuilder::Util qw/ sorted_values /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 DBIx::SearchBuilder::Record - Superclass for records loaded by SearchBuilder
15  
16 =head1 SYNOPSIS
17  
18 package MyRecord;
19 use base qw/DBIx::SearchBuilder::Record/;
20  
21 sub _Init {
22 my $self = shift;
23 my $DBIxHandle = shift; # A DBIx::SearchBuilder::Handle::foo object for your database
24  
25 $self->_Handle($DBIxHandle);
26 $self->Table("Users");
27 }
28  
29 # Tell Record what the primary keys are
30 sub _PrimaryKeys {
31 return ['id'];
32 }
33  
34 # Preferred and most efficient way to specify fields attributes in a derived
35 # class, used by the autoloader to construct Attrib and SetAttrib methods.
36  
37 # read: calling $Object->Foo will return the value of this record's Foo column
38 # write: calling $Object->SetFoo with a single value will set Foo's value in
39 # both the loaded object and the database
40 sub _ClassAccessible {
41 {
42 Tofu => { 'read' => 1, 'write' => 1 },
43 Maz => { 'auto' => 1, },
44 Roo => { 'read' => 1, 'auto' => 1, 'public' => 1, },
45 };
46 }
47  
48 # A subroutine to check a user's password without returning the current value
49 # For security purposes, we didn't expose the Password method above
50 sub IsPassword {
51 my $self = shift;
52 my $try = shift;
53  
54 # note two __s in __Value. Subclasses may muck with _Value, but
55 # they should never touch __Value
56  
57 if ( $try eq $self->__Value('Password') ) {
58 return (1);
59 }
60 else {
61 return (undef);
62 }
63 }
64  
65 # Override DBIx::SearchBuilder::Create to do some checking on create
66 sub Create {
67 my $self = shift;
68 my %fields = (
69 UserId => undef,
70 Password => 'default', #Set a default password
71 @_
72 );
73  
74 # Make sure a userid is specified
75 unless ( $fields{'UserId'} ) {
76 die "No userid specified.";
77 }
78  
79 # Get DBIx::SearchBuilder::Record->Create to do the real work
80 return (
81 $self->SUPER::Create(
82 UserId => $fields{'UserId'},
83 Password => $fields{'Password'},
84 Created => time
85 )
86 );
87 }
88  
89 =head1 DESCRIPTION
90  
91 DBIx::SearchBuilder::Record is designed to work with DBIx::SearchBuilder.
92  
93  
94 =head2 What is it trying to do.
95  
96 DBIx::SearchBuilder::Record abstracts the agony of writing the common and generally
97 simple SQL statements needed to serialize and De-serialize an object to the
98 database. In a traditional system, you would define various methods on
99 your object 'create', 'find', 'modify', and 'delete' being the most common.
100 In each method you would have a SQL statement like:
101  
102 select * from table where value='blah';
103  
104 If you wanted to control what data a user could modify, you would have to
105 do some special magic to make accessors do the right thing. Etc. The
106 problem with this approach is that in a majority of the cases, the SQL is
107 incredibly simple and the code from one method/object to the next was
108 basically the same.
109  
110 <trumpets>
111  
112 Enter, DBIx::SearchBuilder::Record.
113  
114 With Record, you can in the simple case, remove all of that code and
115 replace it by defining two methods and inheriting some code. It's pretty
116 simple, and incredibly powerful. For more complex cases, you can
117 do more complicated things by overriding certain methods. Let's stick with
118 the simple case for now.
119  
120 The two methods in question are L</_Init> and L</_ClassAccessible>. All they
121 really do are define some values and send you on your way. As you might
122 have guessed the '_' means that these are private methods.
123 They will get called by your record object's constructor.
124  
125 =over 4
126  
127 =item '_Init'
128  
129 Defines what table we are talking about, and set a variable to store
130 the database handle.
131  
132 =item '_ClassAccessible
133  
134 Defines what operations may be performed on various data selected
135 from the database. For example you can define fields to be mutable,
136 or immutable, there are a few other options but I don't understand
137 what they do at this time.
138  
139 =back
140  
141 And really, that's it. So let's have some sample code.
142  
143 =head2 An Annotated Example
144  
145 The example code below makes the following assumptions:
146  
147 =over 4
148  
149 =item *
150  
151 The database is 'postgres',
152  
153 =item *
154  
155 The host is 'reason',
156  
157 =item *
158  
159 The login name is 'mhat',
160  
161 =item *
162  
163 The database is called 'example',
164  
165 =item *
166  
167 The table is called 'simple',
168  
169 =item *
170  
171 The table looks like so:
172  
173 id integer not NULL, primary_key(id),
174 foo varchar(10),
175 bar varchar(10)
176  
177 =back
178  
179 First, let's define our record class in a new module named "Simple.pm".
180  
181 000: package Simple;
182 001: use DBIx::SearchBuilder::Record;
183 002: @ISA = (DBIx::SearchBuilder::Record);
184  
185 This should be pretty obvious, name the package, import ::Record and then
186 define ourself as a subclass of ::Record.
187  
188 003:
189 004: sub _Init {
190 005: my $this = shift;
191 006: my $handle = shift;
192 007:
193 008: $this->_Handle($handle);
194 009: $this->Table("Simple");
195 010:
196 011: return ($this);
197 012: }
198  
199 Here we set our handle and table name. While it's not obvious so far, we'll
200 see later that $handle (line: 006) gets passed via C<::Record::new> when a
201 new instance is created. That's actually an important concept: the DB handle
202 is not bound to a single object but rather, it is shared across objects.
203  
204 013:
205 014: sub _ClassAccessible {
206 015: {
207 016: Foo => { 'read' => 1 },
208 017: Bar => { 'read' => 1, 'write' => 1 },
209 018: Id => { 'read' => 1 }
210 019: };
211 020: }
212  
213 What's happening might be obvious, but just in case this method is going to
214 return a reference to a hash. That hash is where our columns are defined,
215 as well as what type of operations are acceptable.
216  
217 021:
218 022: 1;
219  
220 Like all perl modules, this needs to end with a true value.
221  
222 Now, on to the code that will actually *do* something with this object.
223 This code would be placed in your Perl script.
224  
225 000: use DBIx::SearchBuilder::Handle;
226 001: use Simple;
227  
228 Use two packages, the first is where I get the DB handle from, the latter
229 is the object I just created.
230  
231 002:
232 003: my $handle = DBIx::SearchBuilder::Handle->new();
233 004: $handle->Connect( 'Driver' => 'Pg',
234 005: 'Database' => 'test',
235 006: 'Host' => 'reason',
236 007: 'User' => 'mhat',
237 008: 'Password' => '');
238  
239 Creates a new DBIx::SearchBuilder::Handle, and then connects to the database using
240 that handle. Pretty straight forward, the password '' is what I use
241 when there is no password. I could probably leave it blank, but I find
242 it to be more clear to define it.
243  
244 009:
245 010: my $s = Simple->new($handle);
246 011:
247 012: $s->LoadById(1);
248  
249 LoadById is one of four 'LoadBy' methods, as the name suggests it searches
250 for an row in the database that has id='0'. ::SearchBuilder has, what I
251 think is a bug, in that it current requires there to be an id field. More
252 reasonably it also assumes that the id field is unique. LoadById($id) will
253 do undefined things if there is >1 row with the same id.
254  
255 In addition to LoadById, we also have:
256  
257 =over 4
258  
259 =item LoadByCol
260  
261 Takes two arguments, a column name and a value. Again, it will do
262 undefined things if you use non-unique things.
263  
264 =item LoadByCols
265  
266 Takes a hash of columns=>values and returns the *first* to match.
267 First is probably lossy across databases vendors.
268  
269 =item LoadFromHash
270  
271 Populates this record with data from a DBIx::SearchBuilder. I'm
272 currently assuming that DBIx::SearchBuilder is what we use in
273 cases where we expect > 1 record. More on this later.
274  
275 =back
276  
277 Now that we have a populated object, we should do something with it! ::Record
278 automagically generates accessos and mutators for us, so all we need to do
279 is call the methods. Accessors are named <Field>(), and Mutators are named
280 Set<Field>($). On to the example, just appending this to the code from
281 the last example.
282  
283 013:
284 014: print "ID : ", $s->Id(), "\n";
285 015: print "Foo : ", $s->Foo(), "\n";
286 016: print "Bar : ", $s->Bar(), "\n";
287  
288 That's all you have to to get the data. Now to change the data!
289  
290 017:
291 018: $s->SetBar('NewBar');
292  
293 Pretty simple! That's really all there is to it. Set<Field>($) returns
294 a boolean and a string describing the problem. Let's look at an example of
295 what will happen if we try to set a 'Id' which we previously defined as
296 read only.
297  
298 019: my ($res, $str) = $s->SetId('2');
299 020: if (! $res) {
300 021: ## Print the error!
301 022: print "$str\n";
302 023: }
303  
304 The output will be:
305  
306 >> Immutable field
307  
308 Currently Set<Field> updates the data in the database as soon as you call
309 it. In the future I hope to extend ::Record to better support transactional
310 operations, such that updates will only happen when "you" say so.
311  
312 Finally, adding a removing records from the database. ::Record provides a
313 Create method which simply takes a hash of key=>value pairs. The keys
314 exactly map to database fields.
315  
316 023: ## Get a new record object.
317 024: $s1 = Simple->new($handle);
318 025: $s1->Create('Id' => 4,
319 026: 'Foo' => 'Foooooo',
320 027: 'Bar' => 'Barrrrr');
321  
322 Poof! A new row in the database has been created! Now let's delete the
323 object!
324  
325 028:
326 029: $s1 = undef;
327 030: $s1 = Simple->new($handle);
328 031: $s1->LoadById(4);
329 032: $s1->Delete();
330  
331 And it's gone.
332  
333 For simple use, that's more or less all there is to it. In the future, we
334 hope to expand this how-to to discuss using container classes, overloading,
335 etc.
336  
337 =head1 METHOD NAMING
338  
339 Each method has a lower case alias; '_' is used to separate words.
340 For example, the method C<_PrimaryKeys> has the alias C<_primary_keys>.
341  
342 =head1 METHODS
343  
344 =cut
345  
346  
347  
348 =head2 new
349  
350 Instantiate a new record object.
351  
352 =cut
353  
354  
355 2444 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
356 2444 my $proto = shift;
357  
358 2444 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
024440
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
359 2444 my $self = {};
360 2444 bless ($self, $class);
361 2444 $self->_Init(@_);
362  
363 2444 return $self;
364 }
365  
366  
367 # Not yet documented here. Should almost certainly be overloaded.
368 34 ▶sub _Init {
Subroutine _Init: called CC=1 SCAR=0.0
369 34 my $self = shift;
370 34 my $handle = shift;
371 34 $self->_Handle($handle);
372 }
373  
374  
375 =head2 id
376  
377 Returns this row's primary key.
378  
379 =cut
380  
381  
382  
383 21 *id = \&Id;
384  
385 3418 ▶sub Id {
Subroutine Id: called CC=1 SCAR=0.0
Pod undocumented
386 3418 my $pkey = $_[0]->_PrimaryKey();
387 3418 return $_[0]->{'values'}->{ $pkey };
388 }
389  
390  
391 =head2 primary_keys
392  
393 =head2 PrimaryKeys
394  
395 Return a hash of the values of our primary keys for this function.
396  
397 =cut
398  
399  
400  
401  
402 93 ▶sub PrimaryKeys {
Subroutine PrimaryKeys: called CC=1 SCAR=0.0
Pod documented
403 93 my $self = shift;
404 93 return map { $_ => $self->{'values'}->{lc $_} } @{$self->_PrimaryKeys};
405 }
406  
407  
408  
409  
410 2444 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
411 2444 return 1;
412 }
413  
414  
415 45 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=11 SCAR=24.0
416 45 my $self = $_[0];
417  
418 21 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
419 45 my ($Attrib) = ( $AUTOLOAD =~ /::(\w+)$/o );
420  
421 45 ▶ if ( $self->_Accessible( $Attrib, 'read' ) ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($self->_Accessible($Attrib, 'read')) { } 25 20 45
elsif ($self->_Accessible($Attrib, 'record-read')) { } 1 19 20
elsif ($self->_Accessible($Attrib, 'foreign-collection')) { } 1 18 19
elsif ($DBIx::SearchBuilder::Record::AUTOLOAD =~ /.*::[sS]et_?(\w+)/o) { } 9 9 18
elsif ($DBIx::SearchBuilder::Record::AUTOLOAD =~ /.*::(\w+?)_?[oO]bj$/o) { } 2 7 9
elsif ($DBIx::SearchBuilder::Record::AUTOLOAD =~ /.*::[vV]alidate_?(\w+)/o) { } 6 1 7
422 25 ▶ *{$AUTOLOAD} = sub { return ( $_[0]->_Value($Attrib) ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
423 25 goto &$AUTOLOAD;
424 }
425 elsif ( $self->_Accessible( $Attrib, 'record-read') ) {
426 1 ▶ *{$AUTOLOAD} = sub { $_[0]->_ToRecord( $Attrib, $_[0]->__Value($Attrib) ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
427 1 goto &$AUTOLOAD;
428 }
429 elsif ( $self->_Accessible( $Attrib, 'foreign-collection') ) {
430 1 ▶ *{$AUTOLOAD} = sub { $_[0]->_CollectionValue( $Attrib ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
431 1 goto &$AUTOLOAD;
432 }
433 elsif ( $AUTOLOAD =~ /.*::[sS]et_?(\w+)/o ) {
434 9 $Attrib = $1;
435  
436 9 ▶ if ( $self->_Accessible( $Attrib, 'write' ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_Accessible($Attrib, 'write')) { } 6 3 9
elsif ($self->_Accessible($Attrib, 'record-write')) { } 1 2 3
elsif ($self->_Accessible($Attrib, 'read')) { } 1 1 2
437 6 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
438 23 return ( $_[0]->_Set( Field => $Attrib, Value => $_[1] ) );
439 6 };
440 6 goto &$AUTOLOAD;
441 } elsif ( $self->_Accessible( $Attrib, 'record-write') ) {
442 1 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
443 2 my $self = shift;
444 2 my $val = shift;
445  
446 2 ▶ $val = $val->id if UNIVERSAL::isa($val, 'DBIx::SearchBuilder::Record');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($val, "DBIx::SearchBuilder::Record") 1 1 2
447 2 return ( $self->_Set( Field => $Attrib, Value => $val ) );
448 1 };
449 1 goto &$AUTOLOAD;
450 }
451 elsif ( $self->_Accessible( $Attrib, 'read' ) ) {
452 1 ▶ *{$AUTOLOAD} = sub { return ( 0, 'Immutable field' ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
453 1 goto &$AUTOLOAD;
454 }
455 else {
456 1 return ( 0, 'Nonexistant field?' );
457 }
458 }
459 elsif ( $AUTOLOAD =~ /.*::(\w+?)_?[oO]bj$/o ) {
460 2 $Attrib = $1;
461 2 ▶ if ( $self->_Accessible( $Attrib, 'object' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Accessible($Attrib, 'object')) { } 1 1 2
462 1 ▶ *{$AUTOLOAD} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
463 1 return (shift)->_Object(
464 Field => $Attrib,
465 Args => [@_],
466 );
467 1 };
468 1 goto &$AUTOLOAD;
469 }
470 else {
471 1 return ( 0, 'No object mapping for field' );
472 }
473 }
474  
475 #Previously, I checked for writability here. but I'm not sure that's the
476 #right idea. it breaks the ability to do ValidateQueue for a ticket
477 #on creation.
478  
479 elsif ( $AUTOLOAD =~ /.*::[vV]alidate_?(\w+)/o ) {
480 6 $Attrib = $1;
481  
482 6 ▶ *{$AUTOLOAD} = sub { return ( $_[0]->_Validate( $Attrib, $_[1] ) ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
483 6 goto &$AUTOLOAD;
484 }
485  
486 # TODO: if autoload = 0 or 1 _ then a combination of lowercase and _ chars,
487 # turn them into studlycapped phrases
488  
489 else {
490 1 my ( $package, $filename, $line );
491 1 ( $package, $filename, $line ) = caller;
492  
493 1 die "$AUTOLOAD Unimplemented in $package. ($filename line $line) \n";
494 }
495  
496 }
497  
498  
499  
500 =head2 _Accessible KEY MODE
501  
502 Private method.
503  
504 Returns undef unless C<KEY> is accessible in C<MODE> otherwise returns C<MODE> value
505  
506 =cut
507  
508  
509 2333 ▶sub _Accessible {
Subroutine _Accessible: called CC=3 SCAR=11.0
510 2333 my $self = shift;
511 2333 my $attr = shift;
512 2333 ▶ my $mode = lc(shift || '');
Condition100%2/2
shift() || ''
l!l
23321
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
513  
514 2333 my $attribute = $self->_ClassAccessible(@_)->{$attr};
515 2333 ▶ return unless defined $attribute;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attribute 1978 355 2333
516 355 return $attribute->{$mode};
517 }
518  
519  
520  
521 =head2 _PrimaryKeys
522  
523 Return our primary keys. (Subclasses should override this, but our default is that we have one primary key, named 'id'.)
524  
525 =cut
526  
527 3630 ▶sub _PrimaryKeys {
Subroutine _PrimaryKeys: called CC=1 SCAR=0.0
528 3630 my $self = shift;
529 3630 return ['id'];
530 }
531  
532  
533 3476 ▶sub _PrimaryKey {
Subroutine _PrimaryKey: called CC=4 SCAR=15.2
534 3476 my $self = shift;
535 3476 my $pkeys = $self->_PrimaryKeys();
536 3476 ▶ die "No primary key" unless ( ref($pkeys) eq 'ARRAY' and $pkeys->[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pkeys eq "ARRAY" and $pkeys->[0] 0 3476 3476
Condition33%1/3
ref $pkeys eq "ARRAY" and $pkeys->[0]
!ll&&!rl&&r
003476
MC/DC0%0/2
ref $pkeys eq "ARRAY" and $pkeys->[0]
ref $pkeys eq "ARRAY" $pkeys->[0]
Truth table33%1/3
A and B
A= ref $pkeys eq "ARRAY"B= $pkeys->[0]
ABresult
0X0
100
111
537 3476 ▶ die "Too many primary keys" unless ( scalar(@$pkeys) == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$pkeys == 1 0 3476 3476
538 3476 return $pkeys->[0];
539 }
540  
541  
542 =head2 _ClassAccessible
543  
544 An older way to specify fields attributes in a derived class.
545 (The current preferred method is by overriding C<Schema>; if you do
546 this and don't override C<_ClassAccessible>, the module will generate
547 an appropriate C<_ClassAccessible> based on your C<Schema>.)
548  
549 Here's an example declaration:
550  
551 sub _ClassAccessible {
552 {
553 Tofu => { 'read'=>1, 'write'=>1 },
554 Maz => { 'auto'=>1, },
555 Roo => { 'read'=>1, 'auto'=>1, 'public'=>1, },
556 };
557 }
558  
559 =cut
560  
561  
562 53 ▶sub _ClassAccessible {
Subroutine _ClassAccessible: called CC=4 SCAR=22.5
563 53 my $self = shift;
564  
565 53 ▶ return $self->_ClassAccessibleFromSchema if $self->can('Schema');
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("Schema") 53 0 53
566  
567 # XXX This is stub code to deal with the old way we used to do _Accessible
568 # It should never be called by modern code
569  
570 0 my %accessible;
571 0 ▶ while ( my $col = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = shift()) 0 0 0
572 $accessible{$col}->{lc($_)} = 1
573 0 foreach split(/[\/,]/, shift);
574 }
575 0 return(\%accessible);
576 }
577  
578 53 ▶sub _ClassAccessibleFromSchema {
Subroutine _ClassAccessibleFromSchema: called CC=8 SCAR=21.6
579 53 my $self = shift;
580  
581 53 my $accessible = {};
582 53 foreach my $key (@{$self->_PrimaryKeys}) {
583 53 $accessible->{$key} = { 'read' => 1 };
584 };
585  
586 53 my $schema = $self->Schema;
587  
588 53 for my $field (keys %$schema) {
589 104 ▶ if ($schema->{$field}{'TYPE'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($schema->{$field}{'TYPE'}) { } 53 51 104
elsif (my $refclass = $schema->{$field}{'REFERENCES'}) { } 51 0 51
590 53 $accessible->{$field} = { 'read' => 1, 'write' => 1 };
591 } elsif (my $refclass = $schema->{$field}{'REFERENCES'}) {
592 51 ▶ if (UNIVERSAL::isa($refclass, 'DBIx::SearchBuilder::Record')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($refclass, 'DBIx::SearchBuilder::Record')) { } 40 11 51
elsif (UNIVERSAL::isa($refclass, 'DBIx::SearchBuilder')) { } 11 0 11
593 40 ▶ if ($field =~ /(.*)_id$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /(.*)_id$/) { } 0 40 40
594 0 $accessible->{$field} = { 'read' => 1, 'write' => 1 };
595 0 $accessible->{$1} = { 'record-read' => 1, 'column' => $field };
596 } else {
597 40 $accessible->{$field} = { 'record-read' => 1, 'record-write' => 1 };
598 }
599 } elsif (UNIVERSAL::isa($refclass, 'DBIx::SearchBuilder')) {
600 11 $accessible->{$field} = { 'foreign-collection' => 1 };
601 } else {
602 0 warn "Error: $refclass neither Record nor Collection";
603 }
604 }
605 }
606  
607 53 return $accessible;
608 }
609  
610  
611 3 ▶sub _ToRecord {
Subroutine _ToRecord: called CC=7 SCAR=20.6
612 3 my $self = shift;
613 3 my $field = shift;
614 3 my $value = shift;
615  
616 3 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 3 3
617  
618 3 my $schema = $self->Schema;
619 3 ▶ my $description = $schema->{$field} || $schema->{$field . "_id"};
Condition33%1/3
$schema->{$field} || $$schema{$field . '_id'}
l!l&&r!l&&!r
300
MC/DC0%0/2
$schema->{$field} || $$schema{$field . '_id'}
$schema->{$field} $$schema{$field . '_id'}
Truth table33%1/3
A || B
A= $schema->{$field}B= $$schema{$field . '_id'}
ABresult
1X1
011
000
620  
621 3 ▶ die "Can't get schema for $field on $self" unless $description;
Branch: 1 branch
BranchTrueFalseTotal
unless $description 0 3 3
622  
623 3 ▶ return unless $description;
Branch: 1 branch
BranchTrueFalseTotal
unless $description 0 3 3
624  
625 3 ▶ return $value unless $description->{'REFERENCES'};
Branch: 1 branch
BranchTrueFalseTotal
unless $description->{"REFERENCES"} 0 3 3
626  
627 3 my $classname = $description->{'REFERENCES'};
628  
629 3 ▶ return unless UNIVERSAL::isa($classname, 'DBIx::SearchBuilder::Record');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($classname, "DBIx::SearchBuilder::Record") 0 3 3
630  
631 # XXX TODO FIXME perhaps this is not what should be passed to new, but it needs it
632 3 my $object = $classname->new( $self->_Handle );
633 3 $object->LoadById( $value );
634 3 return $object;
635 }
636  
637 2 ▶sub _CollectionValue {
Subroutine _CollectionValue: called CC=4 SCAR=14.1
638 2 my $self = shift;
639  
640 2 my $method_name = shift;
641 2 ▶ return unless defined $method_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method_name 0 2 2
642  
643 2 my $schema = $self->Schema;
644 2 my $description = $schema->{$method_name};
645 2 ▶ return unless $description;
Branch: 1 branch
BranchTrueFalseTotal
unless $description 0 2 2
646  
647 2 my $classname = $description->{'REFERENCES'};
648  
649 2 ▶ return unless UNIVERSAL::isa($classname, 'DBIx::SearchBuilder');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($classname, "DBIx::SearchBuilder") 0 2 2
650  
651 2 my $coll = $classname->new( Handle => $self->_Handle );
652  
653 2 $coll->Limit( FIELD => $description->{'KEY'}, VALUE => $self->id);
654  
655 2 return $coll;
656 }
657  
658 # sub {{{ ReadableAttributes
659  
660 =head2 ReadableAttributes
661  
662 Returns an array of the attributes of this class defined as "read" => 1 in this class' _ClassAccessible datastructure
663  
664 =cut
665  
666 1 ▶sub ReadableAttributes {
Subroutine ReadableAttributes: called CC=2 SCAR=7.1
Pod documented
667 1 my $self = shift;
668 1 my $ca = $self->_ClassAccessible();
669 1 ▶ my @readable = grep { $ca->{$_}->{'read'} or $ca->{$_}->{'record-read'} } sort keys %{$ca};
Condition33%1/3
$ca->{$_}{'read'} || $ca->{$_}{'record-read'}
l!l&&r!l&&!r
500
MC/DC0%0/2
$ca->{$_}{'read'} || $ca->{$_}{'record-read'}
$ca->{$_}{'read'} $ca->{$_}{'record-read'}
Truth table33%1/3
A || B
A= $ca->{$_}{'read'}B= $ca->{$_}{'record-read'}
ABresult
1X1
011
000
670 1 return (@readable);
671 }
672  
673  
674  
675 =head2 WritableAttributes
676  
677 Returns an array of the attributes of this class defined as "write" => 1 in this class' _ClassAccessible datastructure
678  
679 =cut
680  
681 1 ▶sub WritableAttributes {
Subroutine WritableAttributes: called CC=2 SCAR=7.0
Pod documented
682 1 my $self = shift;
683 1 my $ca = $self->_ClassAccessible();
684 1 ▶ my @writable = grep { $ca->{$_}->{'write'} || $ca->{$_}->{'record-write'} } sort keys %{$ca};
Condition66%2/3
$ca->{$_}{'write'} || $ca->{$_}{'record-write'}
l!l&&r!l&&!r
401
MC/DC50%1/2
$ca->{$_}{'write'} || $ca->{$_}{'record-write'}
$ca->{$_}{'write'} $ca->{$_}{'record-write'}
Truth table66%2/3
A || B
A= $ca->{$_}{'write'}B= $ca->{$_}{'record-write'}
ABresult
1X1
011
000
685 1 return @writable;
686 }
687  
688  
689  
690  
691 =head2 __Value
692  
693 Takes a field name and returns that field's value. Subclasses should never
694 override __Value.
695  
696 This method doesn't do any extra work to modify or normalize the encoding of
697 the field's value. Different databases and database drivers have different ways
698 of handling encoding on returned values. For example, L<DBD::Oracle> automatically
699 marks values as UTF-8 if C<NLS_NCHAR> is set to C<AL32UTF8>. Review the documentation
700 for the database driver you are using and test to make sure you handle special
701 characters in returned content.
702  
703 =cut
704  
705  
706 1919 ▶sub __Value {
Subroutine __Value: called CC=5 SCAR=16.3
707 1919 my $self = shift;
708 1919 my $field = lc shift;
709  
710 1919 ▶ $field = $self->_Accessible($field, "column") || $field;
Condition33%1/3
$self->_Accessible($field, 'column') || $field
l!l&&r!l&&!r
019190
MC/DC0%0/2
$self->_Accessible($field, 'column') || $field
$self->_Accessible($field, 'column') $field
Truth table33%1/3
A || B
A= $self->_Accessible($field, 'column')B= $field
ABresult
1X1
011
000
711  
712 1919 ▶ return $self->{'values'}{$field} if $self->{'fetched'}{$field};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fetched"}{$field} 1913 6 1919
713  
714 6 my %pk = $self->PrimaryKeys;
715 6 ▶ return undef if grep !defined, values %pk;
Branch: 1 branch
BranchTrueFalseTotal
if grep((!defined($_)), values %pk) 0 6 6
716  
717 6 my $query = "SELECT $field FROM ". $self->QuotedTableName
718 ." WHERE ". join " AND ", map "$_ = ?", sort keys %pk;
719 6 ▶ my $sth = $self->_Handle->SimpleQuery( $query, sorted_values(%pk) ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $self->_Handle->SimpleQuery($query, sorted_values(%pk)) or return undef 5 1 6
720  
721 5 $self->{'fetched'}{$field} = 1;
722 5 return $self->{'values'}{$field} = ($sth->fetchrow_array)[0];
723 }
724  
725 =head2 _Value
726  
727 _Value takes a single column name and returns that column's value for this row.
728 Subclasses can override _Value to insert custom access control.
729  
730 =cut
731  
732  
733 1749 ▶sub _Value {
Subroutine _Value: called CC=1 SCAR=0.0
734 1749 my $self = shift;
735 1749 return ($self->__Value(@_));
736 }
737  
738  
739  
740 =head2 _Set
741  
742 _Set takes a single column name and a single unquoted value.
743 It updates both the in-memory value of this column and the in-database copy.
744 Subclasses can override _Set to insert custom access control.
745  
746 =cut
747  
748  
749 26 ▶sub _Set {
Subroutine _Set: called CC=1 SCAR=0.0
750 26 my $self = shift;
751 26 return ($self->__Set(@_));
752 }
753  
754  
755  
756  
757 26 ▶sub __Set {
Subroutine __Set: called CC=27 SCAR=39.6
758 26 my $self = shift;
759  
760 26 my %args = (
761 'Field' => undef,
762 'Value' => undef,
763 'IsSQL' => undef,
764 @_
765 );
766  
767 26 $args{'Column'} = delete $args{'Field'};
768 26 $args{'IsSQLFunction'} = delete $args{'IsSQL'};
769  
770 26 my $ret = Class::ReturnValue->new();
771  
772 26 ▶ unless ( $args{'Column'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"Column"}) 1 25 26
773 1 $ret->as_array( 0, 'No column specified' );
774 1 $ret->as_error(
775 errno => 5,
776 do_backtrace => 0,
777 message => "No column specified"
778 );
779 1 return ( $ret->return_value );
780 }
781 25 my $column = lc $args{'Column'};
782  
783 # XXX: OLD behaviour, no_undefs_in_set will go away
784 25 ▶ if ( !defined $args{'Value'} && $self->{'no_undefs_in_set' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{"Value"} and $self->{"no_undefs_in_set"}) 0 25 25
Condition66%2/3
not defined $args{"Value"} and $self->{"no_undefs_in_set"}
!ll&&!rl&&r
1780
MC/DC0%0/2
not defined $args{"Value"} and $self->{"no_undefs_in_set"}
not defined $args{"Value"} $self->{"no_undefs_in_set"}
Truth table66%2/3
not(A) and B
A= not defined $args{"Value"}B= $self->{"no_undefs_in_set"}
ABresult
0X0
100
111
785 0 $ret->as_array( 0, "No value passed to _Set" );
786 0 $ret->as_error(
787 errno => 2,
788 do_backtrace => 0,
789 message => "No value passed to _Set"
790 );
791 0 return ( $ret->return_value );
792 }
793  
794 25 ▶ if ( defined $args{'Value'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'Value'}) { } 17 8 25
795 17 ▶ if ( $args{'Value'} eq '' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"Value"} eq "" and $self->_Accessible($args{"Column"}, "is_numeric") || ($self->_Accessible($args{"Column"}, "type") || "") =~ /INT/i) 3 14 17
Condition75%6/8
$args{"Value"} eq "" and $self->_Accessible($args{"Column"}, "is_numeric") || ($self->_Accessible($args{"Column"}, "type") || "") =~ /INT/i
!ll&&!rl&&r
1313
$self->_Accessible($args{"Column"}, "is_numeric") or ($self->_Accessible($args{"Column"}, "type") || "") =~ /INT/i
l!l&&r!l&&!r
031
$self->_Accessible($args{'Column'}, 'type') || ''
l!l
40
MC/DC33%1/3
$args{"Value"} eq "" and $self->_Accessible($args{"Column"}, "is_numeric") || ($self->_Accessible($args{"Column"}, "type") || "") =~ /INT/i
$args{"Value"} eq "" $self->_Accessible($args{"Column"}, "is_numeric") $self->_Accessible($args{'Column'}, 'type')
Truth table50%2/4
A and B or C
A= $args{"Value"} eq ""B= $self->_Accessible($args{"Column"}, "is_numeric")C= $self->_Accessible($args{'Column'}, 'type')
ABCresult
0XX0
1000
11X1
1011
796 ( $self->_Accessible( $args{'Column'}, 'is_numeric' )
797 || ($self->_Accessible( $args{'Column'}, 'type' ) || '') =~ /INT/i ) )
798 {
799 3 $args{'Value'} = 0;
800 }
801 }
802 else {
803 8 ▶ if ( $self->_Accessible( $args{Column}, 'no_nulls' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Accessible($args{"Column"}, "no_nulls")) 4 4 8
804 4 my $default = $self->_Accessible( $args{Column}, 'default' );
805  
806 4 ▶ if ( defined $default ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) { } 2 2 4
807 2 $args{'Value'} = $default;
808 }
809 else {
810 2 $ret->as_array( 0, 'Illegal value for non-nullable field ' . $args{'Column'} . ": undef/null value provided and no default specified by class" );
811 $ret->as_error(
812 errno => 3,
813 do_backtrace => 0,
814 2 message => "Illegal value for non-nullable field " . $args{'Column'} . ": undef/null value provided and no default specified by class"
815 );
816 2 return ( $ret->return_value );
817 }
818 }
819 }
820  
821 # First, we truncate the value, if we need to.
822 23 $args{'Value'} = $self->TruncateValue( $args{'Column'}, $args{'Value'} );
823  
824 23 my $current_value = $self->__Value($column);
825  
826 23 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{"Value"} || defined $current_value or defined $args{"Value"} and defined $current_value and $args{"Value"} eq $current_value) 3 20 23
Condition100%12/12
not defined $args{"Value"} || defined $current_value or defined $args{"Value"} and defined $current_value and $args{"Value"} eq $current_value
l!l&&r!l&&!r
1220
defined $args{'Value'} || defined $current_value
l!l&&r!l&&!r
1931
defined $args{"Value"} and defined $current_value and $args{"Value"} eq $current_value
!ll&&!rl&&r
5152
defined $args{"Value"} and defined $current_value
!ll&&!rl&&r
3217
MC/DC80%4/5
not defined $args{"Value"} || defined $current_value or defined $args{"Value"} and defined $current_value and $args{"Value"} eq $current_value
defined $args{'Value'} defined $current_value defined $args{"Value"} defined $current_value $args{"Value"} eq $current_value
Truth table55%5/9
not(A || B) or C and D and E
A= defined $args{'Value'}B= defined $current_valueC= defined $args{"Value"}D= defined $current_valueE= $args{"Value"} eq $current_value
ABCDEresult
00XXX1
1X1111
011111
1X0XX0
1X10X0
1X1100
010XX0
0110X0
011100
827 ( !defined $args{'Value'} && !defined $current_value )
828 || ( defined $args{'Value'}
829 && defined $current_value
830 && ( $args{'Value'} eq $current_value ) )
831 )
832 {
833 3 $ret->as_array( 0, "That is already the current value" );
834 3 $ret->as_error(
835 errno => 1,
836 do_backtrace => 0,
837 message => "That is already the current value"
838 );
839 3 return ( $ret->return_value );
840 }
841  
842 20 my $method = "Validate" . $args{'Column'};
843 20 ▶ unless ( $self->$method( $args{'Value'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->$method($args{"Value"})) 1 19 20
844 1 $ret->as_array( 0, 'Illegal value for ' . $args{'Column'} );
845 $ret->as_error(
846 errno => 3,
847 do_backtrace => 0,
848 1 message => "Illegal value for " . $args{'Column'}
849 );
850 1 return ( $ret->return_value );
851 }
852  
853 19 $args{'Table'} = $self->Table();
854 19 $args{'PrimaryKeys'} = { $self->PrimaryKeys() };
855  
856 # The blob handling will destroy $args{'Value'}. But we assign
857 # that back to the object at the end. this works around that
858 19 my $unmunged_value = $args{'Value'};
859  
860 19 ▶ unless ( $self->_Handle->KnowsBLOBs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_Handle->KnowsBLOBs) 0 19 19
861 # Support for databases which don't deal with LOBs automatically
862 0 my $ca = $self->_ClassAccessible();
863 0 my $key = $args{'Column'};
864 0 ▶ if ( ( $ca->{$key}->{'type'} // '' ) =~ /^(text|longtext|clob|longblob|blob|lob)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($ca->{$key}{"type"} // "") =~ /^(text|longtext|clob|longblob|blob|lob)$/i) 0 0 0
Condition0%0/2
$ca->{$key}{"type"} // ""
l!l
00
MC/DC0%0/1
$ca->{$key}{"type"} // ""
$ca->{$key}{"type"}
Truth table0%0/2
A
A= $ca->{$key}{"type"}
Aresult
11
00
865 0 my $bhash = $self->_Handle->BLOBParams( $key, $ca->{$key}->{'type'} );
866 0 ▶ if ( ref($bhash) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bhash eq "HASH" and defined $args{"Value"} && length $args{"Value"} || $self->_Handle->HasSupportForEmptyString) 0 0 0
Condition0%0/9
ref $bhash eq "HASH" and defined $args{"Value"} && length $args{"Value"} || $self->_Handle->HasSupportForEmptyString
!ll&&!rl&&r
000
defined $args{"Value"} and length $args{"Value"} or $self->_Handle->HasSupportForEmptyString
l!l&&r!l&&!r
000
defined $args{"Value"} and length $args{"Value"}
!ll&&!rl&&r
000
MC/DC0%0/4
ref $bhash eq "HASH" and defined $args{"Value"} && length $args{"Value"} || $self->_Handle->HasSupportForEmptyString
ref $bhash eq "HASH" defined $args{"Value"} length $args{"Value"} $self->_Handle->HasSupportForEmptyString
Truth table0%0/6
A and B and C or D
A= ref $bhash eq "HASH"B= defined $args{"Value"}C= length $args{"Value"}D= $self->_Handle->HasSupportForEmptyString
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
867 && ( ( defined $args{'Value'} && length $args{'Value'} ) || $self->_Handle->HasSupportForEmptyString ) )
868 {
869 0 $bhash->{'value'} = $args{'Value'};
870 0 $args{'Value'} = $bhash;
871 }
872 }
873 }
874  
875  
876 19 my $val = $self->_Handle->UpdateRecordValue(%args);
877 19 ▶ unless ($val) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val) 0 19 19
878 my $message =
879 $args{'Column'}
880 . " could not be set to "
881 0 ▶ . ( defined $args{'Value'} ? $args{'Value'} : 'undef' ) . ".";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'Value'} ? : 0 0 0
882 0 $ret->as_array( 0, $message);
883 0 $ret->as_error(
884 errno => 4,
885 do_backtrace => 0,
886 message => $message
887 );
888 0 return ( $ret->return_value );
889 }
890 # If we've performed some sort of "functional update"
891 # then we need to reload the object from the DB to know what's
892 # really going on. (ex SET Cost = Cost+5)
893 19 ▶ if ( $args{'IsSQLFunction'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'IsSQLFunction'}) { } 0 19 19
894 0 $self->Load( $self->Id );
895 }
896 else {
897 19 $self->{'values'}->{"$column"} = $unmunged_value;
898 }
899 19 $ret->as_array( 1, "The new value has been set." );
900 19 return ( $ret->return_value );
901 }
902  
903 =head2 _Canonicalize PARAMHASH
904  
905 This routine massages an input value (VALUE) for FIELD into something that's
906 going to be acceptable.
907  
908 Takes
909  
910 =over
911  
912 =item FIELD
913  
914 =item VALUE
915  
916 =item FUNCTION
917  
918 =back
919  
920  
921 Takes:
922  
923 =over
924  
925 =item FIELD
926  
927 =item VALUE
928  
929 =item FUNCTION
930  
931 =back
932  
933 Returns a replacement VALUE.
934  
935 =cut
936  
937 0 ▶sub _Canonicalize {
Subroutine _Canonicalize: not called CC=1 SCAR=6.9
938 0 my $self = shift;
939 0 my $field = shift;
940  
941  
942  
943 }
944  
945  
946 =head2 _Validate FIELD VALUE
947  
948 Validate that VALUE will be an acceptable value for FIELD.
949  
950 Currently, this routine does nothing whatsoever.
951  
952 If it succeeds (which is always the case right now), returns true. Otherwise returns false.
953  
954 =cut
955  
956  
957  
958  
959 15 ▶sub _Validate {
Subroutine _Validate: called CC=1 SCAR=0.0
960 15 my $self = shift;
961 15 my $field = shift;
962 15 my $value = shift;
963  
964 #Check type of input
965 #If it's null, are nulls permitted?
966 #If it's an int, check the # of bits
967 #If it's a string,
968 #check length
969 #check for nonprintables
970 #If it's a blob, check for length
971 #In an ideal world, if this is a link to another table, check the dependency.
972 15 return(1);
973 }
974  
975  
976  
977 =head2 TruncateValue KEY VALUE
978  
979 Truncate a value that's about to be set so that it will fit inside the database'
980 s idea of how big the column is.
981  
982 (Actually, it looks at SearchBuilder's concept of the database, not directly into the db).
983  
984 =cut
985  
986 293 ▶sub TruncateValue {
Subroutine TruncateValue: called CC=10 SCAR=23.1
Pod documented
987 293 my $self = shift;
988 293 my $key = shift;
989 293 my $value = shift;
990  
991 # We don't need to truncate empty things.
992 293 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 18 275 293
993  
994 275 my $metadata = $self->_ClassAccessible->{$key};
995 275 ▶ return $value unless $metadata;
Branch: 1 branch
BranchTrueFalseTotal
unless $metadata 0 275 275
996  
997 275 my $truncate_to;
998 275 ▶ if ( $metadata->{'length'} && !$metadata->{'is_numeric'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($metadata->{'length'} and not $metadata->{'is_numeric'}) { } 4 271 275
elsif ($metadata->{'type'} and $metadata->{'type'} =~ /char\((\d+)\)/) { } 145 137 282
Condition66%2/3
$metadata->{"length"} and not $metadata->{"is_numeric"}
!ll&&!rl&&r
27104
MC/DC50%1/2
$metadata->{"length"} and not $metadata->{"is_numeric"}
$metadata->{"length"} not $metadata->{"is_numeric"}
Truth table66%2/3
A and not(B)
A= $metadata->{"length"}B= not $metadata->{"is_numeric"}
ABresult
0X0
100
111
999 4 $truncate_to = int $metadata->{'length'};
1000 }
1001 ▶ elsif ($metadata->{'type'} && $metadata->{'type'} =~ /char\((\d+)\)/ ) {
Condition100%3/3
$metadata->{"type"} and $metadata->{"type"} =~ /char\((\d+)\)/
!ll&&!rl&&r
11115145
MC/DC100%2/2
$metadata->{"type"} and $metadata->{"type"} =~ /char\((\d+)\)/
$metadata->{"type"} $metadata->{"type"} =~ /char\((\d+)\)/
Truth table100%3/3
A and B
A= $metadata->{"type"}B= $metadata->{"type"} =~ /char\((\d+)\)/
ABresult
0X0
100
111
1002 145 $truncate_to = $1;
1003 }
1004 275 ▶ return $value unless $truncate_to;
Branch: 1 branch
BranchTrueFalseTotal
unless $truncate_to 126 149 275
1005  
1006 # return asap if length in bytes is smaller than limit
1007 21 ▶ return $value if $truncate_to >= do { use bytes; length $value };
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $truncate_to >= do { use bytes; length $value } 144 5 149
1008  
1009 5 ▶ if ( Encode::is_utf8($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Encode::is_utf8($value)) { } 0 5 5
1010 0 return Encode::decode_utf8(
1011 substr( Encode::encode_utf8( $value ), 0, $truncate_to ),
1012 Encode::FB_QUIET(),
1013 );
1014 }
1015 else {
1016 # XXX: if it's not UTF-8 then why do we convert it to?
1017 5 return Encode::encode_utf8( Encode::decode_utf8 (
1018 substr( $value, 0, $truncate_to ), Encode::FB_QUIET(),
1019 ) );
1020 }
1021 }
1022  
1023  
1024 =head2 _Object
1025  
1026 _Object takes a single column name and an array reference.
1027 It creates new object instance of class specified in _ClassAccessable
1028 structure and calls LoadById on recently created object with the
1029 current column value as argument. It uses the array reference as
1030 the object constructor's arguments.
1031 Subclasses can override _Object to insert custom access control or
1032 define default constructor arguments.
1033  
1034 Note that if you are using a C<Schema> with a C<REFERENCES> field,
1035 this is unnecessary: the method to access the column's value will
1036 automatically turn it into the appropriate object.
1037  
1038 =cut
1039  
1040 1 ▶sub _Object {
Subroutine _Object: called CC=1 SCAR=0.0
1041 1 my $self = shift;
1042 1 return $self->__Object(@_);
1043 }
1044  
1045 1 ▶sub __Object {
Subroutine __Object: called CC=6 SCAR=22.2
1046 1 my $self = shift;
1047 1 my %args = ( Field => '', Args => [], @_ );
1048  
1049 1 my $field = $args{'Field'};
1050 1 my $class = $self->_Accessible( $field, 'object' );
1051  
1052 # Globs magic to be sure that we call 'eval "require $class"' only once
1053 # because eval is quite slow -- cubic@acronis.ru
1054 21 ▶ no strict qw( refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
1055 1 my $vglob = ${ $class . '::' }{'VERSION'};
1056 1 ▶ unless ( $vglob && *$vglob{'SCALAR'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vglob and *$vglob{"SCALAR"}) 0 1 1
Condition50%1/2
$vglob and *$vglob{"SCALAR"}
!ll
01
MC/DC0%0/1
$vglob and *$vglob{"SCALAR"}
$vglob
Truth table50%1/2
A
A= $vglob
Aresult
00
11
1057 0 eval "require $class";
1058 0 ▶ die "Couldn't use $class: $@" if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1059 0 ▶ unless ( $vglob && *$vglob{'SCALAR'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vglob and *$vglob{"SCALAR"}) 0 0 0
Condition0%0/2
$vglob and *$vglob{"SCALAR"}
!ll
00
MC/DC0%0/1
$vglob and *$vglob{"SCALAR"}
$vglob
Truth table0%0/2
A
A= $vglob
Aresult
00
11
1060 0 *{ $class . "::VERSION" } = '-1, By DBIx::SearchBuilder';
1061 }
1062 }
1063  
1064 1 my $object = $class->new( @{ $args{'Args'} } );
1065 1 $object->LoadById( $self->__Value($field) );
1066 1 return $object;
1067 }
1068  
1069  
1070  
1071  
1072 # load should do a bit of overloading
1073 # if we call it with only one argument, we're trying to load by reference.
1074 # if we call it with a passel of arguments, we're trying to load by value
1075 # The latter is primarily important when we've got a whole set of record that we're
1076 # reading in with a recordset class and want to instantiate objefcts for each record.
1077  
1078 =head2 Load
1079  
1080 Takes a single argument, $id. Calls LoadById to retrieve the row whose primary key
1081 is $id
1082  
1083 =cut
1084  
1085  
1086  
1087 49 ▶sub Load {
Subroutine Load: called CC=1 SCAR=0.0
Pod documented
1088 49 my $self = shift;
1089 49 return $self->LoadById(@_);
1090 }
1091  
1092  
1093 =head2 LoadByCol
1094  
1095 Takes two arguments, a column and a value. The column can be any table column
1096 which contains unique values. Behavior when using a non-unique value is
1097 undefined
1098  
1099 =cut
1100  
1101 2 ▶sub LoadByCol {
Subroutine LoadByCol: called CC=1 SCAR=0.0
Pod documented
1102 2 my $self = shift;
1103 2 return $self->LoadByCols(@_);
1104 }
1105  
1106  
1107  
1108 =head2 SelectAllColumns 1|0
1109  
1110 When set to true, forces selection of all columns, bypassing any C<lazy_load>
1111 filtering that would otherwise apply when
1112 C<$DBIx::SearchBuilder::PREFER_LAZY_LOAD> is enabled. When set to false,
1113 restores normal behaviour (all columns by default, or C<lazy_load> filtering
1114 if C<PREFER_LAZY_LOAD> is enabled).
1115  
1116 =cut
1117  
1118 4 ▶sub SelectAllColumns {
Subroutine SelectAllColumns: called CC=2 SCAR=6.9
Pod documented
1119 4 my $self = shift;
1120 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2 4
1121 2 $self->{'_select_all_columns'} = shift;
1122 }
1123 4 return $self->{'_select_all_columns'};
1124 }
1125  
1126 =head2 LoadByCols
1127  
1128 Takes a hash of columns and values. Loads the first record that matches all
1129 keys.
1130  
1131 The hash's keys are the columns to look at.
1132  
1133 The hash's values are either: scalar values to look for
1134 OR has references which contain 'operator' and 'value'
1135  
1136 =cut
1137  
1138  
1139 64 ▶sub LoadByCols {
Subroutine LoadByCols: called CC=15 SCAR=27.3
Pod documented
1140 64 my $self = shift;
1141 64 my %hash = (@_);
1142 64 my (@bind, @phrases);
1143 64 foreach my $key (sort keys %hash) {
1144 66 ▶ if (defined $hash{$key} && $hash{$key} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash{$key} and $hash{$key} ne '') { } 64 2 66
Condition100%3/3
defined $hash{$key} and $hash{$key} ne ""
!ll&&!rl&&r
1164
MC/DC100%2/2
defined $hash{$key} and $hash{$key} ne ""
defined $hash{$key} $hash{$key} ne ""
Truth table100%3/3
A and B
A= defined $hash{$key}B= $hash{$key} ne ""
ABresult
0X0
100
111
1145 64 my $op;
1146 my $value;
1147 64 my $function = "?";
1148 64 ▶ if (ref $hash{$key} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash{$key} eq 'HASH') { } 1 63 64
1149 1 $op = $hash{$key}->{operator};
1150 1 $value = $hash{$key}->{value};
1151 1 ▶ $function = $hash{$key}->{function} || "?";
Condition50%1/2
$hash{$key}{'function'} || '?'
l!l
01
MC/DC0%0/1
$hash{$key}{'function'} || '?'
$hash{$key}{'function'}
Truth table50%1/2
A
A= $hash{$key}{'function'}
Aresult
11
00
1152 } else {
1153 63 $op = '=';
1154 63 $value = $hash{$key};
1155 }
1156  
1157 64 push @phrases, "$key $op $function";
1158 64 push @bind, $value;
1159 }
1160 else {
1161 2 push @phrases, "($key IS NULL OR $key = ?)";
1162 2 my $meta = $self->_ClassAccessible->{$key};
1163 2 ▶ $meta->{'type'} ||= '';
Condition50%1/2
$meta->{"type"} ||= ""
l!l
20
MC/DC0%0/1
$meta->{"type"} ||= ""
$meta->{"type"}
Truth table50%1/2
A
A= $meta->{"type"}
Aresult
11
00
1164 # TODO: type checking should be done in generic way
1165 2 ▶ if ( $meta->{'is_numeric'} || $meta->{'type'} =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{'is_numeric'} or $meta->{'type'} =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i) { } 1 1 2
Condition66%2/3
$meta->{"is_numeric"} or $meta->{"type"} =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i
l!l&&r!l&&!r
011
MC/DC50%1/2
$meta->{"is_numeric"} or $meta->{"type"} =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i
$meta->{"is_numeric"} $meta->{"type"} =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i
Truth table66%2/3
A or B
A= $meta->{"is_numeric"}B= $meta->{"type"} =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i
ABresult
1X1
011
000
1166 1 push @bind, 0;
1167 } else {
1168 1 push @bind, '';
1169 }
1170 }
1171 }
1172  
1173 64 my $select;
1174 64 ▶ if ( $self->{'_select_all_columns'} || !$DBIx::SearchBuilder::PREFER_LAZY_LOAD ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_select_all_columns'} or not $DBIx::SearchBuilder::PREFER_LAZY_LOAD) { } 61 3 64
Condition100%3/3
$self->{"_select_all_columns"} or not $DBIx::SearchBuilder::PREFER_LAZY_LOAD
l!l&&r!l&&!r
2593
MC/DC100%2/2
$self->{"_select_all_columns"} or not $DBIx::SearchBuilder::PREFER_LAZY_LOAD
$self->{"_select_all_columns"} not $DBIx::SearchBuilder::PREFER_LAZY_LOAD
Truth table100%3/3
A or not(B)
A= $self->{"_select_all_columns"}B= not $DBIx::SearchBuilder::PREFER_LAZY_LOAD
ABresult
1X1
011
000
1175 61 $select = '*';
1176 }
1177 else {
1178 3 my $ca = $self->_ClassAccessible;
1179 3 ▶ my @cols = sort grep { !$ca->{$_}{'foreign-collection'} && !$ca->{$_}{'record-read'} && !$ca->{$_}{'lazy_load'} } keys %$ca;
Condition50%3/6
$ca->{$_}{'foreign-collection'} || $ca->{$_}{'record-read'} || $ca->{$_}{'lazy_load'}
l!l&&r!l&&!r
036
$ca->{$_}{"foreign-collection"} or $ca->{$_}{"record-read"}
l!l&&r!l&&!r
009
MC/DC33%1/3
$ca->{$_}{'foreign-collection'} || $ca->{$_}{'record-read'} || $ca->{$_}{'lazy_load'}
$ca->{$_}{"foreign-collection"} $ca->{$_}{"record-read"} $ca->{$_}{'lazy_load'}
Truth table50%2/4
A or B || C
A= $ca->{$_}{"foreign-collection"}B= $ca->{$_}{"record-read"}C= $ca->{$_}{'lazy_load'}
ABCresult
1XX1
01X1
0011
0000
1180 3 ▶ if (@cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cols) 3 0 3
1181 # Always include primary key columns so lazy-fetch can work later
1182 3 my %in_cols = map { $_ => 1 } @cols;
1183 3 push @cols, grep { !$in_cols{$_} } @{ $self->_PrimaryKeys };
1184 }
1185 3 ▶ $select = @cols ? join(', ', @cols) : '*';
Branch: 1 branch
BranchTrueFalseTotal
@cols ? : 3 0 3
1186 }
1187  
1188 64 my $QueryString = "SELECT $select FROM ".$self->QuotedTableName." WHERE ".
1189 join(' AND ', @phrases) ;
1190 64 return ($self->_LoadFromSQL($QueryString, @bind));
1191 }
1192  
1193  
1194  
1195  
1196 =head2 LoadById
1197  
1198 Loads a record by its primary key. Your record class must define a single primary key column.
1199  
1200 =cut
1201  
1202  
1203 58 ▶sub LoadById {
Subroutine LoadById: called CC=2 SCAR=6.9
Pod documented
1204 58 my ($self, $id) = @_;
1205 58 ▶ return $self->LoadByCols( $self->_PrimaryKey, defined $id? $id: 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 57 1 58
1206 }
1207  
1208  
1209  
1210  
1211 =head2 LoadByPrimaryKeys
1212  
1213 Like LoadById with basic support for compound primary keys.
1214  
1215 =cut
1216  
1217  
1218  
1219 3 ▶sub LoadByPrimaryKeys {
Subroutine LoadByPrimaryKeys: called CC=4 SCAR=13.9
Pod documented
1220 3 my $self = shift;
1221 3 ▶ my $data = (ref $_[0] eq 'HASH')? $_[0]: {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 1 2 3
1222  
1223 3 my %cols=();
1224 3 foreach (@{$self->_PrimaryKeys}) {
1225 3 ▶ return (0, "Missing PK field: '$_'") unless defined $data->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{$_} 1 2 3
1226 2 $cols{$_}=$data->{$_};
1227 }
1228 2 return ($self->LoadByCols(%cols));
1229 }
1230  
1231  
1232  
1233  
1234 =head2 LoadFromHash
1235  
1236 Takes a hashref, such as created by DBIx::SearchBuilder and populates this record's
1237 loaded values hash.
1238  
1239 =cut
1240  
1241  
1242  
1243 2238 ▶sub LoadFromHash {
Subroutine LoadFromHash: called CC=2 SCAR=6.9
Pod documented
1244 2238 my $self = shift;
1245 2238 my $hashref = shift;
1246  
1247 2238 foreach my $f ( keys %$hashref ) {
1248 5238 $self->{'fetched'}{lc $f} = 1;
1249 }
1250  
1251 2238 $self->{'values'} = $hashref;
1252 2238 return $self->id();
1253 }
1254  
1255  
1256  
1257 =head2 _LoadFromSQL QUERYSTRING @BIND_VALUES
1258  
1259 Load a record as the result of an SQL statement
1260  
1261 =cut
1262  
1263  
1264  
1265  
1266 68 ▶sub _LoadFromSQL {
Subroutine _LoadFromSQL: called CC=7 SCAR=19.5
1267 68 my $self = shift;
1268 68 my $QueryString = shift;
1269 68 my @bind_values = (@_);
1270  
1271 68 my $sth = $self->_Handle->SimpleQuery( $QueryString, @bind_values );
1272  
1273 #TODO this only gets the first row. we should check if there are more.
1274  
1275 68 ▶ return ( 0, "Couldn't execute query: ".$self->_Handle->dbh->errstr ) unless $sth;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth 1 67 68
1276  
1277 67 $self->{'values'} = $sth->fetchrow_hashref;
1278 67 $self->{'fetched'} = {};
1279 67 ▶ if ( !$self->{'values'} && $sth->err ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"values"} and $sth->err) 0 67 67
Condition66%2/3
not $self->{"values"} and $sth->err
!ll&&!rl&&r
6430
MC/DC0%0/2
not $self->{"values"} and $sth->err
not $self->{"values"} $sth->err
Truth table66%2/3
not(A) and B
A= not $self->{"values"}B= $sth->err
ABresult
0X0
100
111
1280 0 return ( 0, "Couldn't fetch row: ". $sth->err );
1281 }
1282  
1283 67 ▶ unless ( $self->{'values'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"values"}) 3 64 67
1284 3 return ( 0, "Couldn't find row" );
1285 }
1286  
1287 ## I guess to be consistant with the old code, make sure the primary
1288 ## keys exist.
1289  
1290 64 ▶ if( grep { not defined } $self->PrimaryKeys ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined $_;} $self->PrimaryKeys) 1 63 64
1291 1 return ( 0, "Missing a primary key?" );
1292 }
1293  
1294 63 foreach my $f ( keys %{$self->{'values'}} ) {
1295 169 $self->{'fetched'}{lc $f} = 1;
1296 }
1297 63 return ( 1, "Found Object" );
1298  
1299 }
1300  
1301  
1302  
1303  
1304  
1305 =head2 Create
1306  
1307 Takes an array of key-value pairs and drops any keys that aren't known
1308 as columns for this recordtype
1309  
1310 =cut
1311  
1312  
1313  
1314 162 ▶sub Create {
Subroutine Create: called CC=18 SCAR=39.6
Pod documented
1315 162 my $self = shift;
1316 162 my %attribs = @_;
1317  
1318 162 my ($key);
1319 162 foreach $key ( keys %attribs ) {
1320  
1321 269 ▶ if ( $self->_Accessible( $key, 'record-write' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Accessible($key, "record-write")) 3 266 269
1322 $attribs{$key} = $attribs{$key}->id
1323 3 ▶ if UNIVERSAL::isa( $attribs{$key},
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($attribs{$key}, "DBIx::SearchBuilder::Record") 1 2 3
1324 'DBIx::SearchBuilder::Record' );
1325 }
1326  
1327 269 ▶ if ( defined $attribs{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attribs{$key}) { } 254 15 269
1328 254 ▶ if ( $attribs{$key} eq '' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($attribs{$key} eq "" and $self->_Accessible($key, "is_numeric") || ($self->_Accessible($key, "type") || "") =~ /INT/i) 1 253 254
Condition75%6/8
$attribs{$key} eq "" and $self->_Accessible($key, "is_numeric") || ($self->_Accessible($key, "type") || "") =~ /INT/i
!ll&&!rl&&r
25211
$self->_Accessible($key, "is_numeric") or ($self->_Accessible($key, "type") || "") =~ /INT/i
l!l&&r!l&&!r
011
$self->_Accessible($key, 'type') || ''
l!l
20
MC/DC33%1/3
$attribs{$key} eq "" and $self->_Accessible($key, "is_numeric") || ($self->_Accessible($key, "type") || "") =~ /INT/i
$attribs{$key} eq "" $self->_Accessible($key, "is_numeric") $self->_Accessible($key, 'type')
Truth table50%2/4
A and B or C
A= $attribs{$key} eq ""B= $self->_Accessible($key, "is_numeric")C= $self->_Accessible($key, 'type')
ABCresult
0XX0
1000
11X1
1011
1329 ( $self->_Accessible( $key, 'is_numeric' )
1330 || ($self->_Accessible( $key, 'type' ) || '') =~ /INT/i ) )
1331 {
1332 1 $attribs{$key} = 0;
1333 }
1334 }
1335 else {
1336 15 ▶ $attribs{$key} = $self->_Accessible( $key, 'default' )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_Accessible($key, "no_nulls") 1 14 15
1337 if $self->_Accessible( $key, 'no_nulls' );
1338 }
1339  
1340 #Truncate things that are too long for their datatypes
1341 269 $attribs{$key} = $self->TruncateValue( $key => $attribs{$key} );
1342  
1343 }
1344 162 ▶ unless ( $self->_Handle->KnowsBLOBs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_Handle->KnowsBLOBs) 0 162 162
1345  
1346 # Support for databases which don't deal with LOBs automatically
1347 0 my $ca = $self->_ClassAccessible();
1348 0 foreach $key ( keys %attribs ) {
1349 0 my $type = $ca->{$key}->{'type'};
1350 0 ▶ next unless $type && $type =~ /^(text|longtext|clob|blob|lob|longblob)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $type and $type =~ /^(text|longtext|clob|blob|lob|longblob)$/i 0 0 0
Condition0%0/3
$type and $type =~ /^(text|longtext|clob|blob|lob|longblob)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $type =~ /^(text|longtext|clob|blob|lob|longblob)$/i
$type $type =~ /^(text|longtext|clob|blob|lob|longblob)$/i
Truth table0%0/3
A and B
A= $typeB= $type =~ /^(text|longtext|clob|blob|lob|longblob)$/i
ABresult
0X0
100
111
1351  
1352 0 my $bhash = $self->_Handle->BLOBParams( $key, $type );
1353 0 ▶ if ( ref($bhash) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bhash eq "HASH" and defined $attribs{$key} && length $attribs{$key} || $self->_Handle->HasSupportForEmptyString) 0 0 0
Condition0%0/9
ref $bhash eq "HASH" and defined $attribs{$key} && length $attribs{$key} || $self->_Handle->HasSupportForEmptyString
!ll&&!rl&&r
000
defined $attribs{$key} and length $attribs{$key} or $self->_Handle->HasSupportForEmptyString
l!l&&r!l&&!r
000
defined $attribs{$key} and length $attribs{$key}
!ll&&!rl&&r
000
MC/DC0%0/4
ref $bhash eq "HASH" and defined $attribs{$key} && length $attribs{$key} || $self->_Handle->HasSupportForEmptyString
ref $bhash eq "HASH" defined $attribs{$key} length $attribs{$key} $self->_Handle->HasSupportForEmptyString
Truth table0%0/6
A and B and C or D
A= ref $bhash eq "HASH"B= defined $attribs{$key}C= length $attribs{$key}D= $self->_Handle->HasSupportForEmptyString
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
1354 && ( ( defined $attribs{$key} && length $attribs{$key} ) || $self->_Handle->HasSupportForEmptyString ) )
1355 {
1356 0 $bhash->{'value'} = $attribs{$key};
1357 0 $attribs{$key} = $bhash;
1358 }
1359 }
1360 }
1361 162 return ( $self->_Handle->Insert( $self->Table, %attribs ) );
1362 }
1363  
1364  
1365 =head2 Delete
1366  
1367 Delete this record from the database. On failure return a Class::ReturnValue with the error. On success, return 1;
1368  
1369 =cut
1370  
1371 21 *delete = \&Delete;
1372  
1373 2 ▶sub Delete {
Subroutine Delete: called CC=1 SCAR=0.0
Pod documented
1374 2 $_[0]->__Delete;
1375 }
1376  
1377 2 ▶sub __Delete {
Subroutine __Delete: called CC=3 SCAR=11.1
1378 2 my $self = shift;
1379  
1380 #TODO Check to make sure the key's not already listed.
1381 #TODO Update internal data structure
1382  
1383 ## Constructs the where clause.
1384 2 my @bind=();
1385 2 my %pkeys=$self->PrimaryKeys();
1386 2 my $where = 'WHERE ';
1387 2 foreach my $key (sort keys %pkeys) {
1388 2 $where .= $key . "=?" . " AND ";
1389 2 push (@bind, $pkeys{$key});
1390 }
1391  
1392 2 $where =~ s/AND\s$//;
1393 2 my $QueryString = "DELETE FROM ". $self->QuotedTableName . ' ' . $where;
1394 2 my $return = $self->_Handle->SimpleQuery($QueryString, @bind);
1395  
1396 2 ▶ if (UNIVERSAL::isa($return, 'Class::ReturnValue')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($return, 'Class::ReturnValue')) { } 0 2 2
1397 0 return ($return);
1398 } else {
1399 2 return(1);
1400 }
1401 }
1402  
1403  
1404  
1405  
1406  
1407 =head2 Table
1408  
1409 Returns or sets the name of the current Table
1410  
1411 =cut
1412  
1413  
1414  
1415 2640 ▶sub Table {
Subroutine Table: called CC=2 SCAR=6.9
Pod documented
1416 2640 my $self = shift;
1417 2640 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2410 230 2640
1418 2410 $self->{'table'} = shift;
1419 }
1420 2640 return ($self->{'table'});
1421 }
1422  
1423 =head2 QuotedTableName
1424  
1425 Returns the name of current Table, or the table provided as an argument, including any quoting
1426 based on yje Handle's QuoteTableNames flag and driver method.
1427  
1428 =cut
1429  
1430 72 ▶sub QuotedTableName {
Subroutine QuotedTableName: called CC=5 SCAR=18.1
Pod documented
1431 72 my ($self, $name) = @_;
1432 72 ▶ unless ($name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 72 0 72
1433 72 ▶ return $self->{'_quoted_table'} if defined $self->{'_quoted_table'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_quoted_table"} 8 64 72
1434 64 ▶ $self->{'_quoted_table'}
Branch: 1 branch
BranchTrueFalseTotal
$self->_Handle->QuoteTableNames ? : 0 64 64
1435 = $self->_Handle->QuoteTableNames ? $self->_Handle->QuoteName( $self->Table ) : $self->Table;
1436 64 return $self->{'_quoted_table'};
1437 }
1438 0 ▶ return $self->_Handle->QuoteTableNames ? $self->_Handle->QuoteName($name) : $name;
Branch: 1 branch
BranchTrueFalseTotal
$self->_Handle->QuoteTableNames ? : 0 0 0
1439 }
1440  
1441 =head2 _Handle
1442  
1443 Returns or sets the current DBIx::SearchBuilder::Handle object
1444  
1445 =cut
1446  
1447  
1448 2952 ▶sub _Handle {
Subroutine _Handle: called CC=2 SCAR=6.9
1449 2952 my $self = shift;
1450 2952 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2444 508 2952
1451 2444 $self->{'DBIxHandle'} = shift;
1452 }
1453 2952 return ($self->{'DBIxHandle'});
1454 }
1455  
1456  
1457 21 ▶if( eval { require capitalization } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require capitalization } }) 0 21 21
1458 0 capitalization->unimport( __PACKAGE__ );
1459 }
1460  
1461 21 1;
« SearchBuilder/Handle/Oracle.pm ↑ Summary SearchBuilder/SchemaGenerator.pm »