| 1 | package DBomb::Meta::ColumnInfo; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | DBomb::Meta::ColumnInfo - Meta data about a column. | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | =cut | ||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | our $VERSION = '$Revision: 1.15 $'; | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use Carp qw(carp croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use Carp::Assert; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | use Class::MethodMaker | ||||||||||
| 18 | 1 | ▶ | 'new_with_init' => 'new_internal', | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 'get_set' => [qw(table_info), # table_info | ||||||||||
| 20 | qw(name), # column name | ||||||||||
| 21 | qw(fq_name), # fully qualified -- read only | ||||||||||
| 22 | qw(accessor), # accessor name | ||||||||||
| 23 | qw(attr), # attribute name | ||||||||||
| 24 | qw(select_when_null), # list of 1 element. promote NULLs to this value. default: [] | ||||||||||
| 25 | qw(update_when_empty), # list of 1 element. promote empty string to this value. default: [] | ||||||||||
| 26 | ], | ||||||||||
| 27 | 'boolean' => [qw(is_resolved), | ||||||||||
| 28 | qw(is_expr), # Is an expression column (not a real column) | ||||||||||
| 29 | qw(is_generated), # database generates it (auto_increment, etc.) | ||||||||||
| 30 | qw(select_trim), # trim whitespace | ||||||||||
| 31 | qw(update_trim), # trim whitespace | ||||||||||
| 32 | qw(recurse_on_copy), # deep copy | ||||||||||
| 33 | ], | ||||||||||
| 34 | 1 | ; | |||||||||
| 35 | |||||||||||
| 36 | ## new ColumnInfo($table_info, $name, $opts) | ||||||||||
| 37 | sub new | ||||||||||
| 38 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 39 | ## This new() is actually a class factory, following a parameterized singleton pattern | ||||||||||
| 40 | ## The real new() is new_internal(). | ||||||||||
| 41 | 0 | ▶ | my $class = ref($_[0]) ? ref(shift) : shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | my ($table_info,$name,$opts) = @_; | |||||||||
| 43 | |||||||||||
| 44 | 0 | assert(defined $table_info); | |||||||||
| 45 | 0 | assert(defined $name); | |||||||||
| 46 | |||||||||||
| 47 | 0 | my $cols = DBomb->tables->{$table_info->name}->columns; | |||||||||
| 48 | 0 | ▶ | if (exists $cols->{$name}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | croak "duplicate column name '$name' for table " . $table_info->name; | |||||||||
| 50 | } | ||||||||||
| 51 | else{ | ||||||||||
| 52 | 0 | $table_info->add_column($class->new_internal($table_info, $name, $opts)); | |||||||||
| 53 | } | ||||||||||
| 54 | 0 | return $cols->{$name}; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub init | ||||||||||
| 58 | 0 | ▶ | { | ||||||||
|
Subroutine
init: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||
| 59 | 0 | my ($self, $table_info, $name, $opts) = @_; | |||||||||
| 60 | |||||||||||
| 61 | 0 | assert(defined($table_info), "table_info defined"); | |||||||||
| 62 | 0 | assert(defined($name), "column name defined"); | |||||||||
| 63 | 0 | assert(defined($opts), "options defined"); | |||||||||
| 64 | |||||||||||
| 65 | 0 | $self->table_info($table_info); | |||||||||
| 66 | 0 | $self->name($name); | |||||||||
| 67 | 0 | $self->fq_name($self->table_info->name .".". $self->name); | |||||||||
| 68 | 0 | $self->is_resolved(1); ## nothing to resolve | |||||||||
| 69 | 0 | $self->select_trim(0); | |||||||||
| 70 | 0 | $self->update_trim(0); | |||||||||
| 71 | 0 | $self->recurse_on_copy(0); | |||||||||
| 72 | 0 | $self->select_when_null([]); | |||||||||
| 73 | 0 | $self->update_when_empty([]); | |||||||||
| 74 | |||||||||||
| 75 | ## defaults | ||||||||||
| 76 | 0 | $self->accessor($name); | |||||||||
| 77 | 0 | $self->attr("__dbo_column: $name"); | |||||||||
| 78 | 0 | ▶ | $self->enable_string_mangle if $opts->{'string_mangle'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | |||||||||||
| 80 | 0 | for (keys %$opts) { | |||||||||
| 81 | 0 | my $v = $opts->{$_}; | |||||||||
| 82 | 0 | ▶ | /^column$/ && do{ $self->name($v); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | ▶ | /^accessor$/ && do{ $self->accessor($v); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | ▶ | /^attr$/ && do{ $self->attr($v); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 0 | ▶ | /^expr(?:ession)?$/ && do{ $self->name($v); $self->fq_name($v); $self->is_expr(1); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | ▶ | /^is_generated|auto_increment$/ && do{ $self->is_generated($v); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | ▶ | /^select_trim$/ && do{ $self->select_trim($v); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 0 | ▶ | /^update_trim$/ && do{ $self->update_trim($v); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | ▶ | /^recurse_on_copy$/ && do{ $self->recurse_on_copy($v); next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | ▶ | /^select_when_null$/ && do{ $self->select_when_null->[0] = $v; next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | ▶ | /^update_when_empty$/ && do{ $self->update_when_empty->[0] = $v; next}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | ▶ | /^string_mangle$/ && do { next; }; # handled above. | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 0 | croak "unrecognized option '$_'"; | |||||||||
| 94 | } | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | sub is_in_primary_key | ||||||||||
| 98 | 0 | ▶ | { | ||||||||
|
Subroutine
is_in_primary_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 99 | 0 | my $self = shift; | |||||||||
| 100 | 0 | assert(@_ == 0); | |||||||||
| 101 | 0 | exists $self->table_info->primary_key->columns->{$self->name}; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | sub enable_string_mangle | ||||||||||
| 105 | 0 | ▶ | { | ||||||||
|
Subroutine
enable_string_mangle: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 106 | 0 | my $self = shift; | |||||||||
| 107 | 0 | $self->select_trim(1); | |||||||||
| 108 | 0 | $self->update_trim(1); | |||||||||
| 109 | 0 | $self->select_when_null->[0] = ''; | |||||||||
| 110 | 0 | $self->update_when_empty->[0] = undef; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 0 | ▶ | sub resolve { 1 } | ||||||||
|
Subroutine
resolve: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 114 | |||||||||||
| 115 | 1 | 1; | |||||||||
| 116 | __END__ | ||||||||||