| 1 | package ODS::Table; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use YAOO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use ODS::Utils qw/clone/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use ODS::Utils qw/load build_temp_class/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 3 | auto_build; | |||||||||
| 15 | |||||||||||
| 16 | 3 | has storage_class => isa(string); | |||||||||
| 17 | |||||||||||
| 18 | 3 | has storage => isa(object); | |||||||||
| 19 | |||||||||||
| 20 | 3 | has table_class => isa(string); | |||||||||
| 21 | |||||||||||
| 22 | 3 | has resultset_class => isa(string); | |||||||||
| 23 | |||||||||||
| 24 | 3 | has resultset => isa(object); | |||||||||
| 25 | |||||||||||
| 26 | 3 | has name => isa(string); | |||||||||
| 27 | |||||||||||
| 28 | 3 | has columns => isa(ordered_hash), default(1); | |||||||||
| 29 | |||||||||||
| 30 | 3 | has row_class => isa(string); | |||||||||
| 31 | |||||||||||
| 32 | 3 | has rows => isa(array); | |||||||||
| 33 | |||||||||||
| 34 | 3 | has options => isa(hash); | |||||||||
| 35 | |||||||||||
| 36 | 3 | has keyfield => isa(string); | |||||||||
| 37 | |||||||||||
| 38 | sub add_column { | ||||||||||
| 39 | 36 | ▶ | my ($self, @args) = @_; | ||||||||
|
Subroutine
add_column: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||
| 40 | |||||||||||
| 41 | 36 | my $name = shift @args; | |||||||||
| 42 | |||||||||||
| 43 | 36 | ▶ | if ($self->columns->{$name}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | croak sprintf "Column %s is already defined in the %s table", | |||||||||
| 45 | $name, $self->name; | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 36 | ▶ | if (scalar @args % 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | croak "The column definition for %s does not contain an even number of key/values in the %s table.", | |||||||||
| 50 | $name, $self->name; | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 36 | my %column = @args; | |||||||||
| 54 | 36 | $column{name} = $name; | |||||||||
| 55 | 36 | ▶ | if (! $column{type}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 16 | $column{type} = 'string'; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 36 | ▶ | if ($column{keyfield}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 2 | $self->keyfield($name); | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 36 | my $module = 'ODS::Table::Column::' . ucfirst($column{type}); | |||||||||
| 64 | |||||||||||
| 65 | 36 | load $module; | |||||||||
| 66 | |||||||||||
| 67 | 36 | my $column = $module->new(\%column); | |||||||||
| 68 | |||||||||||
| 69 | 36 | $self->columns->{$name} = $column; | |||||||||
| 70 | |||||||||||
| 71 | 36 | return $self; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | sub connect { | ||||||||||
| 75 | 3 | ▶ | my ($self, $package, $storage, $connect) = (shift, shift, shift, shift); | ||||||||
|
Subroutine
connect: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | 3 | ▶ | if (ref $storage) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $connect = $storage; | |||||||||
| 80 | 0 | $storage = undef; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 3 | $self->table_class($package); | |||||||||
| 84 | |||||||||||
| 85 | 3 | (my $resultset = $package) =~ s/Table/ResultSet2/g; | |||||||||
| 86 | |||||||||||
| 87 | 3 | eval { | |||||||||
| 88 | 3 | load $resultset | |||||||||
| 89 | }; | ||||||||||
| 90 | |||||||||||
| 91 | 3 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 3 | $resultset = 'ODS::Table::ResultSet'; | |||||||||
| 93 | 3 | load $resultset; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 3 | $self->resultset_class($resultset); | |||||||||
| 97 | |||||||||||
| 98 | 3 | (my $row = $package) =~ s/Table/Row/g; | |||||||||
| 99 | |||||||||||
| 100 | 3 | eval { | |||||||||
| 101 | 3 | load $row | |||||||||
| 102 | }; | ||||||||||
| 103 | |||||||||||
| 104 | 3 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 3 | $row = build_temp_class('ODS::Table::Row'); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 3 | $self->row_class($row); | |||||||||
| 109 | |||||||||||
| 110 | 3 | ▶ | $self->storage_class($storage) if $storage; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | |||||||||||
| 112 | 3 | $storage = $self->storage_class; | |||||||||
| 113 | |||||||||||
| 114 | 3 | my $module = 'ODS::Storage::' . $storage; | |||||||||
| 115 | |||||||||||
| 116 | 3 | load $module; | |||||||||
| 117 | |||||||||||
| 118 | 2 | ▶ | $self->storage($module->connect(%{$connect || {}}, table => $self)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | |||||||||||
| 120 | 2 | return $self->resultset($self->resultset_class->new(table => $self, @_)); | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | 3 | 1; | |||||||||
| 125 | |||||||||||
| 126 | __END__ | ||||||||||