File Coverage

blib/lib/DBR/Config/Field/Common.pm
Criterion Covered Total %
statement 34 49 69.3
branch 8 14 57.1
condition n/a
subroutine 9 21 42.8
pod 0 15 0.0
total 51 99 51.5


line stmt bran cond sub pod time code
1             # the contents of this file are Copyright (c) 2009 Daniel Norman
2             # This program is free software; you can redistribute it and/or
3             # modify it under the terms of the GNU General Public License as
4             # published by the Free Software Foundation.
5              
6             package DBR::Config::Field::Common;
7              
8 18     18   122 use strict;
  18         41  
  18         662  
9 18     18   105 use base 'DBR::Common';
  18         45  
  18         1985  
10 18     18   108 use Carp;
  18         37  
  18         1747  
11              
12             use constant ({
13             # Object fields
14 18         16806 O_xname => 0,
15             O_session => 1,
16             O_index => 2,
17             O_table_alias => 3,
18             O_alias_flag => 4,
19 18     18   118 });
  18         29  
20              
21 0     0 0 0 sub makevalue{ undef }
22 0     0 0 0 sub table_id { undef };
23 2025     2025 0 7000 sub field_id { undef };
24 0     0 0 0 sub name { confess "shouldn't get here" };
25 0     0 0 0 sub is_pkey { undef }
26 0     0 0 0 sub table { undef }
27 1     1 0 7 sub is_numeric{ undef }
28 0     0 0 0 sub translator { undef }
29 0     0 0 0 sub is_readonly { 0 }
30 0     0 0 0 sub testsub { sub { 0 } }
  0     0   0  
31 0     0 0 0 sub default_val { undef }
32              
33             sub table_alias{
34 5437     5437 0 7958 my $self = shift;
35 5437         8672 my $set = shift;
36 5437 100       17007 if($set){
37 34         136 return $self->[O_table_alias] = $set;
38             }
39              
40 5403         11159 return $self->[O_table_alias];
41              
42             }
43              
44             sub index{
45 2787     2787 0 10392 my $self = shift;
46 2787         3502 my $set = shift;
47              
48 2787 100       6675 if(defined($set)){
49 2473 50       5937 croak "Cannot set the index on a field object twice" if defined( $self->[O_index] ); # I want this to fail obnoxiously
50 2473         7465 $self->[O_index] = $set;
51 2473         10887 return 1;
52             }
53              
54 314         1123 return $self->[O_index];
55             }
56              
57 0     0 0 0 sub validate { 1 }
58              
59             sub sql {
60 5381     5381 0 9412 my $self = shift;
61 5381         18603 my $name = $self->name;
62 5381         13765 my $alias = $self->table_alias;
63              
64 5381         9942 my $sql;
65 5381 100       11065 $sql = $alias . '.' if $alias;
66 5381         8258 $sql .= $name;
67              
68 5381 50       21791 if(defined($self->[O_alias_flag])){
69              
70 0 0       0 if ( $self->{O_alias_flag} == 1 ) {
    0          
71 0         0 $sql .= " AS $name";
72             } elsif ( $self->{O_alias_flag} == 2 ) {
73 0         0 $sql .= " AS '$alias.$name'";
74             }
75              
76             }
77              
78 5381         50089 return $sql;
79             }
80              
81 0     0     sub _session { $_[0]->[O_session] }
82              
83             1;