« blib/lib/blx/xsdsql/generator/sql/generic/handle/create_table.pm
↑ Summary
blib/lib/blx/xsdsql/schema_repository/sql/generic/name_generator.pm »
| 1 | package blx::xsdsql::connection; | ||||||||||
| 2 | 1 | ▶ | use strict; # use strict is for PBP | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Filter::Include; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | include blx::xsdsql::include; | ||||||||||
| 5 | #line 6 | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use base qw(blx::xsdsql::ut::common_interfaces); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | our %_ATTRS_R:Constant( | |||||||||
| 10 | 1 | ▶ | OUTPUT_NAMESPACE_INSTANCE => sub { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | my $self=$_[0]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | if (defined (my $output_namespace=$self->{OUTPUT_NAMESPACE})) { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | if (defined (my $inst=$self->{OUTPUT_NAMESPACE_INSTANCE}->{$output_namespace})) { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | return $inst; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | undef | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | } | ||||||||||
| 19 | 1 | ▶ | ,CONNECTION_LIST => sub { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | my $self=$_[0]; | ||||||||||
| 21 | if (defined (my $output_namespace=$self->{OUTPUT_NAMESPACE})) { | ||||||||||
| 22 | if (defined (my $inst=$self->{OUTPUT_NAMESPACE_INSTANCE}->{$output_namespace})) { | ||||||||||
| 23 | return $inst->get_attrs_value(qw(CONNECTION_LIST)); | ||||||||||
| 24 | } | ||||||||||
| 25 | } | ||||||||||
| 26 | undef; | ||||||||||
| 27 | } | ||||||||||
| 28 | ,DB_NAMESPACE => sub { | ||||||||||
| 29 | my $self=$_[0]; | ||||||||||
| 30 | if (defined (my $output_namespace=$self->{OUTPUT_NAMESPACE})) { | ||||||||||
| 31 | if (defined (my $inst=$self->{OUTPUT_NAMESPACE_INSTANCE}->{$output_namespace})) { | ||||||||||
| 32 | return $inst->get_attrs_value(qw(DB_NAMESPACE)); | ||||||||||
| 33 | } | ||||||||||
| 34 | } | ||||||||||
| 35 | undef; | ||||||||||
| 36 | } | ||||||||||
| 37 | ,ERR => sub { | ||||||||||
| 38 | my $self=$_[0]; | ||||||||||
| 39 | return $self->{ERR} if defined $self->{ERR}; | ||||||||||
| 40 | if (defined (my $output_namespace=$self->{OUTPUT_NAMESPACE})) { | ||||||||||
| 41 | if (defined (my $inst=$self->{OUTPUT_NAMESPACE_INSTANCE}->{$output_namespace})) { | ||||||||||
| 42 | return $inst->get_attrs_value(qw(ERR)); | ||||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | undef; | ||||||||||
| 46 | } | ||||||||||
| 47 | 1 | ▶ | ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | 1 | our %_ATTRS_W:Constant( | |||||||||
| 50 | map { my $a=$_;($a,sub { croak $a.": this attribute is not writeable"}) } keys %_ATTRS_R | ||||||||||
| 51 | 1 | ▶ | ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub _get_attrs_w { return \%_ATTRS_W; } | ||||||||
|
Subroutine
_get_attrs_w: not called CC=1 SCAR=6.9
| |||||||||||
| 55 | 0 | ▶ | sub _get_attrs_r { return \%_ATTRS_R; } | ||||||||
|
Subroutine
_get_attrs_r: not called CC=1 SCAR=6.9
| |||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 58 | 0 | my ($class,%params)=@_; | |||||||||
| 59 | 0 | my $s=delete $params{CONNECTION_STRING}; | |||||||||
| 60 | 0 | my $self=bless {},$class; | |||||||||
| 61 | 0 | $self->set_attrs_value(%params); | |||||||||
| 62 | 0 | ▶ | $self->do_connection_list($s,%params) if defined $s; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $self; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub do_connection_list { | ||||||||
|
Subroutine
do_connection_list: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||
| 67 | 0 | my ($self,$connection_string,%params)=@_; | |||||||||
| 68 | 0 | for my $k(grep($_ ne 'OUTPUT_NAMESPACE_INSTANCE',keys %_ATTRS_R)) { delete $self->{$k}; } | |||||||||
| 69 | 0 | ▶ | unless (defined $connection_string) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | $self->{ERR}="no connection string specify"; | |||||||||
| 71 | 0 | return; | |||||||||
| 72 | } | ||||||||||
| 73 | 0 | $self->{CONNECTION_STRING}=$connection_string; | |||||||||
| 74 | 0 | ▶ | my $output_namespace=$connection_string=~s/^(\w+)::// ? $1 : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 0 | ▶ | $output_namespace='sql' unless defined $output_namespace; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | $self->{OUTPUT_NAMESPACE}=$output_namespace; | |||||||||
| 77 | 0 | ▶ | unless (defined $self->{OUTPUT_NAMESPACE_INSTANCE}->{$output_namespace}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | my $class='blx::xsdsql::connection::'.$output_namespace.'::connection'; | |||||||||
| 79 | 0 | local $@; | |||||||||
| 80 | 0 | eval "use $class"; ## no critic | |||||||||
| 81 | 0 | ▶ | if (my $s=$@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | ▶ | if ($s=~/^\s*Can't locate/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | $self->{ERR}="$output_namespace: unknow output_namespace"; | |||||||||
| 84 | 0 | return; | |||||||||
| 85 | } | ||||||||||
| 86 | else { | ||||||||||
| 87 | 0 | croak $s; | |||||||||
| 88 | } | ||||||||||
| 89 | } | ||||||||||
| 90 | 0 | $self->{OUTPUT_NAMESPACE_INSTANCE}->{$output_namespace}=$class->new; | |||||||||
| 91 | } | ||||||||||
| 92 | 0 | my $inst=$self->{OUTPUT_NAMESPACE_INSTANCE}->{$output_namespace}; | |||||||||
| 93 | my $r=$inst->do_connection_list( | ||||||||||
| 94 | $connection_string | ||||||||||
| 95 | ,%params | ||||||||||
| 96 | ,CONNECTION_STRING => $self->{CONNECTION_STRING} | ||||||||||
| 97 | ,OUTPUT_NAMESPACE => $self->{OUTPUT_NAMESPACE} | ||||||||||
| 98 | 0 | ); | |||||||||
| 99 | 0 | ▶ | return unless $r; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | $self->{CONNECTION_LIST}=$inst->get_attrs_value(qw(CONNECTION_LIST)); | |||||||||
| 101 | 0 | $self; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | sub get_output_namespace { $_[0]->get_attrs_value(qw(OUTPUT_NAMESPACE))} | ||||||||
|
Subroutine
get_output_namespace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 105 | |||||||||||
| 106 | 0 | ▶ | sub get_db_namespace { $_[0]->get_attrs_value(qw(DB_NAMESPACE))} | ||||||||
|
Subroutine
get_db_namespace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub get_last_error { $_[0]->get_attrs_value(qw(ERR)) } | ||||||||
|
Subroutine
get_last_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 109 | |||||||||||
| 110 | 0 | ▶ | sub get_connection_list { | ||||||||
|
Subroutine
get_connection_list: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 111 | 0 | my ($self,%params)=@_; | |||||||||
| 112 | 0 | my $connection_list=$self->get_attrs_value(qw(CONNECTION_LIST)); | |||||||||
| 113 | 0 | ▶ | if (defined $connection_list) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | ▶ | return wantarray ? @$connection_list : $connection_list; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | } | ||||||||||
| 116 | 0 | ▶ | wantarray ? () : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | sub get_output_namespace_instance { return $_[0]->get_attrs_value(qw(OUTPUT_NAMESPACE_INSTANCE))} | ||||||||
|
Subroutine
get_output_namespace_instance: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 120 | |||||||||||
| 121 | 0 | ▶ | sub get_attribute_names { | ||||||||
|
Subroutine
get_attribute_names: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 122 | 0 | my ($self,%params)=@_; | |||||||||
| 123 | 0 | my @k=keys %_ATTRS_R; | |||||||||
| 124 | 0 | ▶ | wantarray ? @k : \@k; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 1 | 1; | |||||||||
| 128 | |||||||||||
| 129 | __END__ | ||||||||||