| 1 | |||||||||||||||||||||||||||||
| 2 | package SQL::Admin::Catalog; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = v0.5.0; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | ###################################################################### | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use SQL::Admin::Catalog::Schema; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use SQL::Admin::Catalog::Sequence; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use SQL::Admin::Catalog::Index; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use SQL::Admin::Catalog::Table; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use SQL::Admin::Catalog::Table::Column; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use SQL::Admin::Catalog::Table::PrimaryKey; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use SQL::Admin::Catalog::Table::Unique; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use SQL::Admin::Catalog::Table::ForeignKey; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | ###################################################################### | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use List::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | our $NAME_TRANSFORM = { | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | NAME => sub { $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | NAME_lc => sub { lc $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | NAME_uc => sub { uc $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 1 | }; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | ###################################################################### | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | my $class_map = { | |||||||||||||||||||||||||||
| 33 | schema => 'SQL::Admin::Catalog::Schema', | ||||||||||||||||||||||||||||
| 34 | sequence => 'SQL::Admin::Catalog::Sequence', | ||||||||||||||||||||||||||||
| 35 | table => 'SQL::Admin::Catalog::Table', | ||||||||||||||||||||||||||||
| 36 | index => 'SQL::Admin::Catalog::Index', | ||||||||||||||||||||||||||||
| 37 | column => 'SQL::Admin::Catalog::Table::Column', | ||||||||||||||||||||||||||||
| 38 | primary_key => 'SQL::Admin::Catalog::Table::PrimaryKey', | ||||||||||||||||||||||||||||
| 39 | unique => 'SQL::Admin::Catalog::Table::Unique', | ||||||||||||||||||||||||||||
| 40 | foreign_key => 'SQL::Admin::Catalog::Table::ForeignKey', | ||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | ###################################################################### | ||||||||||||||||||||||||||||
| 44 | ###################################################################### | ||||||||||||||||||||||||||||
| 45 | 8 | ▶ | sub new { # ; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 8 | my ($class, %param) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | $param{FetchHashKeyName} = 'NAME_uc' | ||||||||||||||||||||||||||||
| 49 | 8 | ▶ | unless $param{FetchHashKeyName}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | $param{FetchHashKeyName} = 'NAME' | ||||||||||||||||||||||||||||
| 52 | 8 | ▶ | unless exists $NAME_TRANSFORM->{ $param{FetchHashKeyName} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | ################################################################## | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | bless { | ||||||||||||||||||||||||||||
| 57 | name_transform => $NAME_TRANSFORM->{ $param{FetchHashKeyName} }, | ||||||||||||||||||||||||||||
| 58 | 8 | ▶ | allow_redeclare => 1, | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | (map +($_ => {}), keys %$class_map), | ||||||||||||||||||||||||||||
| 61 | }, ref $class || $class; | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | ###################################################################### | ||||||||||||||||||||||||||||
| 66 | ###################################################################### | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub catalog { # ; | ||||||||||||||||||||||||||
|
Subroutine
catalog: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 0 | $_[0]; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | ###################################################################### | ||||||||||||||||||||||||||||
| 73 | ###################################################################### | ||||||||||||||||||||||||||||
| 74 | 20 | ▶ | sub add { # ; | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=8 SCAR=21.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 20 | my ($self, $type, %param) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 20 | ▶ | return unless exists $class_map->{$type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 20 | ▶ | my $typemap = $self->{$type} ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{$type} ||= {}
MC/DC0%0/1
$self->{$type} ||= {}
$self->{$type}
Truth table50%1/2
A
A= $self->{$type}
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | ################################################################## | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | $param{schema} = $self->{default_schema} | ||||||||||||||||||||||||||||
| 84 | 20 | ▶ | if ! $param{schema} and $self->{default_schema}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $param{"schema"} and $self->{"default_schema"}
MC/DC0%0/2
not $param{"schema"} and $self->{"default_schema"}
not $param{"schema"}
$self->{"default_schema"}
Truth table66%2/3
not(A) and B
A= not $param{"schema"}B= $self->{"default_schema"}
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 20 | my $obj = $self->get ($type, %param, catalog => $self); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | ################################################################## | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 20 | ▶ | if (my $schema = $obj->schema) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 11 | ▶ | $self->{schema}{$schema} ||= $class_map->{schema}->new (name => $schema); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"schema"}{$schema} ||= $class_map->{"schema"}->new("name", $schema)
MC/DC0%0/2
$self->{"schema"}{$schema} ||= $class_map->{"schema"}->new("name", $schema)
$self->{"schema"}{$schema}
$class_map->{"schema"}->new("name", $schema)
Truth table66%2/3
A ||= B
A= $self->{"schema"}{$schema}B= $class_map->{"schema"}->new("name", $schema)
| |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | ################################################################## | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 20 | ▶ | $typemap->{ $obj->fullname } ||= $obj; | ||||||||||||||||||||||||||
|
Condition66%2/3
$$typemap{$obj->fullname} ||= $obj
MC/DC0%0/2
$$typemap{$obj->fullname} ||= $obj
$$typemap{$obj->fullname}
$obj
Truth table66%2/3
A ||= B
A= $$typemap{$obj->fullname}B= $obj
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | ###################################################################### | ||||||||||||||||||||||||||||
| 101 | ###################################################################### | ||||||||||||||||||||||||||||
| 102 | 23 | ▶ | sub get { # ; | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 23 | my ($self, $type, %param) = @_; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | return | ||||||||||||||||||||||||||||
| 106 | 23 | ▶ | unless exists $class_map->{$type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | ################################################################## | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # my $obj = $class_map->{$type}->new (%param, catalog => $self); | ||||||||||||||||||||||||||||
| 111 | 23 | my $obj = $class_map->{$type}->new (%param); | |||||||||||||||||||||||||||
| 112 | 23 | my $key = $obj->fullname; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | $obj = $self->{$type}{ $key } | ||||||||||||||||||||||||||||
| 115 | 23 | ▶ | if exists $self->{$type}{ $key }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | ################################################################## | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 23 | return $obj; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | ###################################################################### | ||||||||||||||||||||||||||||
| 124 | ###################################################################### | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub exists { # ; | ||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 0 | my ($self, $type, @list) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | return | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | unless exists $class_map->{$type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my $key; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | $key = 1 == @list ? $list[0] : $class_map->{$type}->new (@list); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $key = $key->fullname if ref $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | return exists $self->{$type}{ $key } && $key; | ||||||||||||||||||||||||||
|
Condition0%0/3
exists $self->{$type}{$key} && $key
MC/DC0%0/2
exists $self->{$type}{$key} && $key
exists $self->{$type}{$key}
$key
Truth table0%0/3
A && B
A= exists $self->{$type}{$key}B= $key
| |||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | ###################################################################### | ||||||||||||||||||||||||||||
| 140 | ###################################################################### | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub list { # ; | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | +{ %{ $self->{$type} || {} } }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{$type} || {}
MC/DC0%0/1
$self->{$type} || {}
$self->{$type}
Truth table0%0/2
A
A= $self->{$type}
| |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | ###################################################################### | ||||||||||||||||||||||||||||
| 149 | ###################################################################### | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub add_statement { # ; | ||||||||||||||||||||||||||
|
Subroutine
add_statement: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | my $list = $self->{statements} ||= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"statements"} ||= []
MC/DC0%0/1
$self->{"statements"} ||= []
$self->{"statements"}
Truth table0%0/2
A
A= $self->{"statements"}
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | push @$list, @_; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | ###################################################################### | ||||||||||||||||||||||||||||
| 159 | ###################################################################### | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub load { # ; | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 161 | 0 | my ($self, $driver, @params) = @_; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | $driver = SQL::Admin->get_driver ($driver, @{ shift @params || [] } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
shift @params || []
MC/DC0%0/1
shift @params || []
shift @params
Truth table0%0/2
A
A= shift @params
| |||||||||||||||||||||||||||||
| 164 | unless ref $driver; | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | $driver->load ($self, @params); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | $self; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | ###################################################################### | ||||||||||||||||||||||||||||
| 173 | ###################################################################### | ||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub save { # ; | ||||||||||||||||||||||||||
|
Subroutine
save: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 175 | 0 | my ($self, $driver, @params) = @_; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $driver = SQL::Admin->get_driver ($driver, @{ shift @params || [] } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
shift @params || []
MC/DC0%0/1
shift @params || []
shift @params
Truth table0%0/2
A
A= shift @params
| |||||||||||||||||||||||||||||
| 178 | unless ref $driver; | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | $driver->save ($self, @params); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | $self; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | ###################################################################### | ||||||||||||||||||||||||||||
| 187 | ###################################################################### | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | package SQL::Admin::Catalog; | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 1 | 1; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | __END__ | ||||||||||||||||||||||||||||