| 1 | package DBIO::Schema; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Schema class and connection container for DBIO applications | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 316 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 316 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 316 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 316 | ▶ | use base 'DBIO::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 316 | ▶ | use DBIO::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 316 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 316 | ▶ | use Scalar::Util qw/weaken blessed/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 316 | ▶ | use DBIO::Util qw(refcount quote_sub is_exception scope_guard old_mro file_path); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 316 | ▶ | use DBIO::Skills; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 316 | ▶ | use DBIO::Deploy::Base (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 316 | ▶ | use DBIO::Storage::Composed; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 316 | ▶ | use Devel::GlobalDestruction; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 316 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 316 | __PACKAGE__->mk_classdata('class_mappings' => {}); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 316 | __PACKAGE__->mk_classdata('source_registrations' => {}); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 316 | __PACKAGE__->mk_classdata('storage_type' => '::DBI'); | |||||||||||||||||||||||||||||||||||||||||
| 24 | # What a declared driver that does not fit what it meets leads to (ADR 0059): | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # a warning by default, an error with driver_strict, nothing without | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # driver_warnings. Read by DBIO::Storage::DBI::_driver_mismatch. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 316 | __PACKAGE__->mk_classdata('driver_strict' => 0); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 316 | __PACKAGE__->mk_classdata('driver_warnings' => 1); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 316 | __PACKAGE__->mk_classdata('storage'); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 316 | __PACKAGE__->mk_classdata('exception_action'); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 316 | ▶ | __PACKAGE__->mk_classdata('stacktrace' => ($ENV{DBIO_TRACE} || 0)); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'DBIO_TRACE'} || 0
MC/DC100%1/1
$ENV{'DBIO_TRACE'} || 0
$ENV{'DBIO_TRACE'}
Truth table100%2/2
A
A= $ENV{'DBIO_TRACE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 316 | __PACKAGE__->mk_classdata('default_resultset_attributes' => {}); | |||||||||||||||||||||||||||||||||||||||||
| 33 | # Optional per-schema overrides for DBIO::Skills. Keys are skill names (the | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # leading dbio- is optional), values are markdown strings. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 316 | __PACKAGE__->mk_classdata('skills'); | |||||||||||||||||||||||||||||||||||||||||
| 36 | # Ordered list of storage extension layer packages registered for this schema | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # (see L</register_storage_layer>). Defaults to an empty arrayref shared across | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # subclasses via inherited class data, so register_storage_layer must copy | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # before appending -- never mutate the arrayref in place. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 316 | __PACKAGE__->mk_classdata('storage_layers' => []); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # Pre-pends our classname to the given relative classname or | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # class namespace, unless there is a '+' prefix, which will | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # be stripped. | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 33 | ▶ | sub _expand_relative_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_relative_name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 33 | my ($class, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 33 | ▶ | $name =~ s/^\+// or $name = "${class}::${name}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 33 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # Finds all modules in the supplied namespace, or if omitted in the | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # namespace of $class. Untaints all findings as they can be assumed | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # to be safe | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 28 | ▶ | sub _findallmod { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_findallmod: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 28 | require Module::Find; | |||||||||||||||||||||||||||||||||||||||||
| 57 | return map | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 28 | ▶ | { $_ =~ /(.+)/ } # untaint result | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$_[1] || ref $_[0] || $_[0]
$_[1] or ref $_[0]
MC/DC0%0/3
$_[1] || ref $_[0] || $_[0]
$_[1]
ref $_[0]
$_[0]
Truth table25%1/4
A or B || C
A= $_[1]B= ref $_[0]C= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | Module::Find::findallmod( $_[1] || ref $_[0] || $_[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # returns a hash of $shortname => $fullname for every package | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # found in the given namespaces ($shortname is with the $fullname's | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # namespace stripped off) | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 28 | ▶ | sub _map_namespaces { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_map_namespaces: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 28 | my ($me, $namespaces) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 28 | my %res; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 28 | for my $ns (@$namespaces) { | |||||||||||||||||||||||||||||||||||||||||
| 71 | $res{ substr($_, length "${ns}::") } = $_ | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 30 | for $me->_findallmod($ns); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 28 | \%res; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # returns the result_source_instance for the passed class/object, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # or dies with an informative message (used by load_namespaces) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 264 | ▶ | sub _ns_get_rsrc_instance { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ns_get_rsrc_instance: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 264 | my $me = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 264 | ▶ | my $rs_class = ref ($_[0]) || $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 264 | ▶ | return try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 264 | $rs_class->result_source_instance | |||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | $me->throw_exception ( | |||||||||||||||||||||||||||||||||||||||||
| 88 | "Attempt to load_namespaces() class $rs_class failed - are you sure this is a real Result Class?: $_" | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 264 | }; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 14 | ▶ | sub load_namespaces { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_namespaces: called CC=26 SCAR=32.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 14 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 14 | ▶ | my $result_namespace = delete $args{result_namespace} || 'Result'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'result_namespace'} || 'Result'
MC/DC100%1/1
delete $args{'result_namespace'} || 'Result'
delete $args{'result_namespace'}
Truth table100%2/2
A
A= delete $args{'result_namespace'}
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 14 | ▶ | my $resultset_namespace = delete $args{resultset_namespace} || 'ResultSet'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'resultset_namespace'} || 'ResultSet'
MC/DC100%1/1
delete $args{'resultset_namespace'} || 'ResultSet'
delete $args{'resultset_namespace'}
Truth table100%2/2
A
A= delete $args{'resultset_namespace'}
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 14 | my $default_resultset_class = delete $args{default_resultset_class}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 14 | ▶ | $default_resultset_class = $class->_expand_relative_name($default_resultset_class) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | if $default_resultset_class; | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | $class->throw_exception('load_namespaces: unknown option(s): ' | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | . join(q{,}, map { qq{'$_'} } keys %args)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | if scalar keys %args; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 14 | for my $arg ($result_namespace, $resultset_namespace) { | |||||||||||||||||||||||||||||||||||||||||
| 109 | 28 | ▶ | $arg = [ $arg ] if ( $arg and ! ref $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$arg and not ref $arg
MC/DC50%1/2
$arg and not ref $arg
$arg
not ref $arg
Truth table66%2/3
A and not(B)
A= $argB= not ref $arg
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 28 | ▶ | $class->throw_exception('load_namespaces: namespace arguments must be ' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | . 'a simple string or an arrayref') | ||||||||||||||||||||||||||||||||||||||||||
| 113 | if ref($arg) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 28 | $_ = $class->_expand_relative_name($_) for (@$arg); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 14 | my $results_by_source_name = $class->_map_namespaces($result_namespace); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 14 | my $resultsets_by_source_name = $class->_map_namespaces($resultset_namespace); | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 14 | my @to_register; | |||||||||||||||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 316 | ▶ | no warnings qw/redefine/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 14 | ▶ | local *Class::C3::reinitialize = sub { } if old_mro; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 316 | ▶ | use warnings qw/redefine/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # ensure classes are loaded and attached in inheritance order | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 14 | for my $result_class (values %$results_by_source_name) { | |||||||||||||||||||||||||||||||||||||||||
| 129 | 130 | $class->ensure_class_loaded($result_class); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 14 | my %inh_idx; | |||||||||||||||||||||||||||||||||||||||||
| 132 | my @source_names_by_subclass_last = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 14 | ($inh_idx{$a} ||= | |||||||||||||||||||||||||||||||||||||||||
| 135 | 63 | ▶ | scalar @{mro::get_linear_isa( $results_by_source_name->{$a} )} | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$inh_idx{$b} ||= scalar @{&mro::get_linear_isa($results_by_source_name->{$b});}
MC/DC100%1/1
$inh_idx{$b} ||= scalar @{&mro::get_linear_isa($results_by_source_name->{$b});}
$inh_idx{$b}
Truth table100%2/2
A
A= $inh_idx{$b}
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | <=> | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | ($inh_idx{$b} ||= | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 120 | ▶ | scalar @{mro::get_linear_isa( $results_by_source_name->{$b} )} | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$inh_idx{$a} ||= scalar @{&mro::get_linear_isa($results_by_source_name->{$a});}
MC/DC100%1/1
$inh_idx{$a} ||= scalar @{&mro::get_linear_isa($results_by_source_name->{$a});}
$inh_idx{$a}
Truth table100%2/2
A
A= $inh_idx{$a}
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | } keys(%$results_by_source_name); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 14 | foreach my $source_name (@source_names_by_subclass_last) { | |||||||||||||||||||||||||||||||||||||||||
| 147 | 128 | my $result_class = $results_by_source_name->{$source_name}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 128 | my $preset_resultset_class = $class->_ns_get_rsrc_instance ($result_class)->resultset_class; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 127 | my $found_resultset_class = delete $resultsets_by_source_name->{$source_name}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 127 | ▶ | if($preset_resultset_class && $preset_resultset_class ne 'DBIO::ResultSet') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$preset_resultset_class and $preset_resultset_class ne "DBIO::ResultSet"
MC/DC50%1/2
$preset_resultset_class and $preset_resultset_class ne "DBIO::ResultSet"
$preset_resultset_class
$preset_resultset_class ne "DBIO::ResultSet"
Truth table66%2/3
A and B
A= $preset_resultset_classB= $preset_resultset_class ne "DBIO::ResultSet"
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 7 | ▶ | if($found_resultset_class && $found_resultset_class ne $preset_resultset_class) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$found_resultset_class and $found_resultset_class ne $preset_resultset_class
MC/DC100%2/2
$found_resultset_class and $found_resultset_class ne $preset_resultset_class
$found_resultset_class
$found_resultset_class ne $preset_resultset_class
Truth table100%3/3
A and B
A= $found_resultset_classB= $found_resultset_class ne $preset_resultset_class
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | carp "We found ResultSet class '$found_resultset_class' matching '$results_by_source_name->{$source_name}', but it seems " | |||||||||||||||||||||||||||||||||||||||||
| 155 | . "that you had already set the '$results_by_source_name->{$source_name}' resultet to '$preset_resultset_class' instead"; | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # elsif - there may be *no* default_resultset_class, in which case we fallback to | ||||||||||||||||||||||||||||||||||||||||||
| 159 | # DBIO::Resultset and there is nothing to check | ||||||||||||||||||||||||||||||||||||||||||
| 160 | ▶ | elsif($found_resultset_class ||= $default_resultset_class) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$found_resultset_class ||= $default_resultset_class
MC/DC100%2/2
$found_resultset_class ||= $default_resultset_class
$found_resultset_class
$default_resultset_class
Truth table100%3/3
A ||= B
A= $found_resultset_classB= $default_resultset_class
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 9 | $class->ensure_class_loaded($found_resultset_class); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 9 | ▶ | if(!$found_resultset_class->isa("DBIO::ResultSet")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | carp "load_namespaces found ResultSet class '$found_resultset_class' that does not subclass DBIO::ResultSet"; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 9 | $class->_ns_get_rsrc_instance ($result_class)->resultset_class($found_resultset_class); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 127 | ▶ | my $source_name = $class->_ns_get_rsrc_instance ($result_class)->source_name || $source_name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$class->_ns_get_rsrc_instance($result_class)->source_name || $source_name
MC/DC0%0/2
$class->_ns_get_rsrc_instance($result_class)->source_name || $source_name
$class->_ns_get_rsrc_instance($result_class)->source_name
$source_name
Truth table33%1/3
A || B
A= $class->_ns_get_rsrc_instance($result_class)->source_nameB= $source_name
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 127 | push(@to_register, [ $source_name, $result_class ]); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 13 | foreach (sort keys %$resultsets_by_source_name) { | |||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | carp "load_namespaces found ResultSet class '$resultsets_by_source_name->{$_}' " | |||||||||||||||||||||||||||||||||||||||||
| 177 | .'with no corresponding Result class'; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 13 | ▶ | Class::C3->reinitialize if old_mro; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 13 | $class->register_class(@$_) for (@to_register); | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 265 | ▶ | sub load_classes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_classes: called CC=15 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 265 | my ($class, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 265 | my %comps_for; | |||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 265 | ▶ | if (@params) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 265 | foreach my $param (@params) { | |||||||||||||||||||||||||||||||||||||||||
| 195 | 9993 | ▶ | if (ref $param eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | # filter out commented entries | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my @modules = grep { $_ !~ /^#/ } @$param; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | push (@{$comps_for{$class}}, @modules); | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | elsif (ref $param eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # more than one namespace possible | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 260 | for my $comp ( keys %$param ) { | |||||||||||||||||||||||||||||||||||||||||
| 204 | # filter out commented entries | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 260 | my @modules = grep { $_ !~ /^#/ } @{$param->{$comp}}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 260 | push (@{$comps_for{$comp}}, @modules); | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # filter out commented entries | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 9733 | ▶ | push (@{$comps_for{$class}}, $param) if $param !~ /^#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my @comp = map { substr $_, length "${class}::" } | |||||||||||||||||||||||||||||||||||||||||
| 217 | $class->_findallmod($class); | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $comps_for{$class} = \@comp; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 265 | my @to_register; | |||||||||||||||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 316 | ▶ | no warnings qw/redefine/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 265 | ▶ | local *Class::C3::reinitialize = sub { } if old_mro; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 316 | ▶ | use warnings qw/redefine/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 265 | foreach my $prefix (keys %comps_for) { | |||||||||||||||||||||||||||||||||||||||||
| 228 | 265 | ▶ | foreach my $comp (@{$comps_for{$prefix}||[]}) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$comps_for{$prefix} || []
MC/DC0%0/1
$comps_for{$prefix} || []
$comps_for{$prefix}
Truth table50%1/2
A
A= $comps_for{$prefix}
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 11533 | my $comp_class = "${prefix}::${comp}"; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 11533 | $class->ensure_class_loaded($comp_class); | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 11531 | my $snsub = $comp_class->can('source_name'); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 11531 | ▶ | if(! $snsub ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | carp "Failed to load $comp_class. Can't find source_name method. Is $comp_class really a full DBIO result class? Fix it, move it elsewhere, or make your load_classes call more specific."; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 11530 | ▶ | $comp = $snsub->($comp_class) || $comp; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
&$snsub($comp_class) || $comp
MC/DC0%0/2
&$snsub($comp_class) || $comp
&$snsub($comp_class)
$comp
Truth table66%2/3
A || B
A= &$snsub($comp_class)B= $comp
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 11530 | push(@to_register, [ $comp, $comp_class ]); | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 263 | ▶ | Class::C3->reinitialize if old_mro; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 263 | foreach my $to (@to_register) { | |||||||||||||||||||||||||||||||||||||||||
| 246 | 11530 | $class->register_class(@$to); | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 1812 | ▶ | sub connect { shift->clone->connection(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 3983 | ▶ | sub resultset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resultset: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 3983 | my ($self, $source_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 3983 | ▶ | $self->throw_exception('resultset() expects a source name') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | unless defined $source_name; | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 3983 | return $self->source($source_name)->resultset; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | # Through an array, not `sort ...` as the last expression: sort in scalar | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # context is undefined, and the count is what this returned there all along. | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 3739 | ▶ | sub sources { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sources: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 3739 | my @source_names = sort keys %{shift->source_registrations}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 3739 | return @source_names; | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 106746 | ▶ | sub source { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
source: called CC=11 SCAR=28.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 106746 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 106746 | ▶ | $self->throw_exception("source() expects a source name") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | unless @_; | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 106745 | my $source_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 106745 | my $sreg = $self->source_registrations; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 106745 | ▶ | return $sreg->{$source_name} if exists $sreg->{$source_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # if we got here, they probably passed a full class name | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 6066 | my $mapped = $self->class_mappings->{$source_name}; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 6066 | ▶ | if ($mapped && exists $sreg->{$mapped}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mapped and exists $sreg->{$mapped}
MC/DC50%1/2
$mapped and exists $sreg->{$mapped}
$mapped
exists $sreg->{$mapped}
Truth table66%2/3
A and B
A= $mappedB= exists $sreg->{$mapped}
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 6062 | return $sreg->{$mapped}; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | # Provide helpful "did you mean?" suggestions | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | my @sources = sort keys %$sreg; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | my @suggestions; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 4 | for my $s (@sources) { | |||||||||||||||||||||||||||||||||||||||||
| 291 | # Simple edit distance check -- suggest if name is close | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $dist = _simple_distance(lc $source_name, lc $s); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | push @suggestions, $s if $dist <= 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 4 | my $msg = "Can't find source for ${source_name}"; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | ▶ | if (@suggestions) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $msg .= ". Did you mean: " . join(', ', @suggestions) . "?"; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | elsif (@sources) { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | $msg .= ". Available sources: " . join(', ', @sources[0..($#sources > 9 ? 9 : $#sources)]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | $msg .= ", ..." if @sources > 10; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 4 | $self->throw_exception($msg); | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # Simple Levenshtein distance for "did you mean?" suggestions | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | sub _simple_distance { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_simple_distance: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my ($s, $t) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my @s = split //, $s; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my @t = split //, $t; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $n = scalar @s; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $m = scalar @t; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | return $m unless $n; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | return $n unless $m; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my @d; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $d[$_][0] = $_ for 0 .. $n; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $d[0][$_] = $_ for 0 .. $m; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | for my $i (1 .. $n) { | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | for my $j (1 .. $m) { | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | my $cost = ($s[$i-1] eq $t[$j-1]) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $d[$i][$j] = _min( | |||||||||||||||||||||||||||||||||||||||||
| 325 | $d[$i-1][$j] + 1, | ||||||||||||||||||||||||||||||||||||||||||
| 326 | $d[$i][$j-1] + 1, | ||||||||||||||||||||||||||||||||||||||||||
| 327 | $d[$i-1][$j-1] + $cost, | ||||||||||||||||||||||||||||||||||||||||||
| 328 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | return $d[$n][$m]; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub _min { my $m = shift; $m = $_ < $m ? $_ : $m for @_; $m } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_min: not called CC=3 SCAR=24.8
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | # --- DateTime convenience methods --- | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sub datetime_parser { shift->storage->datetime_parser } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetime_parser: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub parse_datetime { shift->datetime_parser->parse_datetime(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_datetime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | sub format_datetime { shift->datetime_parser->format_datetime(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_datetime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 45 | ▶ | sub class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 45 | return shift->source(shift)->result_class; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 24 | ▶ | sub txn_do { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_do: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 24 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | ('txn_do called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 24 | $self->storage->txn_do(@_); | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 763 | ▶ | sub txn_scope_guard { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_scope_guard: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 763 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 763 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | ('txn_scope_guard called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 763 | $self->storage->txn_scope_guard(@_); | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | sub txn_begin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_begin: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | ('txn_begin called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $self->storage->txn_begin; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | sub txn_commit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_commit: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | ('txn_commit called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $self->storage->txn_commit; | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub txn_rollback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
txn_rollback: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | ('txn_rollback called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $self->storage->txn_rollback; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | sub populate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
populate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my ($self, $name, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | my $rs = $self->resultset($name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | or $self->throw_exception("'$name' is not a resultset"); | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | return $rs->populate($data); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 1885 | ▶ | sub connection { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 1885 | my ($self, @info) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 1885 | ▶ | return $self if !@info && $self->storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @info and $self->storage
MC/DC0%0/2
not @info and $self->storage
not @info
$self->storage
Truth table66%2/3
not(A) and B
A= not @infoB= $self->storage
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | # Per-connection skills override: ->connect($dsn, $u, $p, { skills => {...} }). | ||||||||||||||||||||||||||||||||||||||||||
| 417 | # Pulled out of the connect attrs (it is not a DBI parameter) and stored on | ||||||||||||||||||||||||||||||||||||||||||
| 418 | # the instance, so it shadows the class-level skills() default for this | ||||||||||||||||||||||||||||||||||||||||||
| 419 | # connected schema only. See DBIO::Skills and L</skill>. | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 1885 | for my $arg (@info) { | |||||||||||||||||||||||||||||||||||||||||
| 421 | 2508 | ▶ | next unless ref $arg eq 'HASH' && exists $arg->{skills}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $arg eq "HASH" and exists $arg->{"skills"}
MC/DC100%2/2
ref $arg eq "HASH" and exists $arg->{"skills"}
ref $arg eq "HASH"
exists $arg->{"skills"}
Truth table100%3/3
A and B
A= ref $arg eq "HASH"B= exists $arg->{"skills"}
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | $self->skills(delete $arg->{skills}); | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 1885 | my ($storage_class, $args) = $self->_resolved_storage_type; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | # No schema without a driver (ADR 0067): refused before any storage is built. | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 1885 | $self->_refuse_undeclared_driver($storage_class); | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | # Compose any registered storage extension layers over the resolved base | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # storage class (one behaviour, one transport -- see DBIO::Storage::Composed). | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # The synthesised class is what actually gets instantiated below; when the | ||||||||||||||||||||||||||||||||||||||||||
| 433 | # declared driver adapts to its access path (_adapt_to_access_path, during | ||||||||||||||||||||||||||||||||||||||||||
| 434 | # DBIO::Storage::DBI::_determine_driver) the same layers are re-composed over | ||||||||||||||||||||||||||||||||||||||||||
| 435 | # the adapted class. Skipped cleanly when nothing is registered. | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 1857 | my @storage_layers = @{ $self->storage_layers }; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 1857 | ▶ | $storage_class = DBIO::Storage::Composed->compose($storage_class, \@storage_layers) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | if @storage_layers; | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 1857 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 1857 | $self->ensure_class_loaded ($storage_class); | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 32 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 32 | $self->throw_exception( | |||||||||||||||||||||||||||||||||||||||||
| 445 | "Unable to load storage class ${storage_class}: $_" | ||||||||||||||||||||||||||||||||||||||||||
| 446 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 1857 | }; | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 1821 | ▶ | my $storage = $storage_class->new( $self => $args||{} ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args || {}
MC/DC100%1/1
$args || {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 1821 | $storage->connect_info(\@info); | |||||||||||||||||||||||||||||||||||||||||
| 451 | 1807 | $self->storage($storage); | |||||||||||||||||||||||||||||||||||||||||
| 452 | 1807 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | # The storage class storage_type names, with its +/:: prefix resolved, and its | ||||||||||||||||||||||||||||||||||||||||||
| 456 | # constructor arguments (undef for a plain class name). | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 1899 | ▶ | sub _resolved_storage_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolved_storage_type: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 1899 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 1899 | ▶ | my ($storage_class, $args) = ref $self->storage_type | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | ? $self->_normalize_storage_type($self->storage_type) | ||||||||||||||||||||||||||||||||||||||||||
| 462 | : ($self->storage_type, undef) | ||||||||||||||||||||||||||||||||||||||||||
| 463 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 1899 | $storage_class =~ s/^\+//; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 1899 | $storage_class =~ s/^::/DBIO::Storage::/; | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 1899 | return ($storage_class, $args); | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | # A schema always has a driver (ADR 0067): a storage class resolving to the | ||||||||||||||||||||||||||||||||||||||||||
| 472 | # generic DBIO::Storage::DBI declares none, and is refused. $hint is added to | ||||||||||||||||||||||||||||||||||||||||||
| 473 | # the message by a caller that knows more (DBIO::Replicated). | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 1892 | ▶ | sub _refuse_undeclared_driver { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refuse_undeclared_driver: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 1892 | my ($self, $storage_class, $hint) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 1892 | ▶ | return unless $storage_class eq 'DBIO::Storage::DBI'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 29 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 29 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | "Schema class $class declares no driver: its storage class is the " | ||||||||||||||||||||||||||||||||||||||||||
| 482 | . 'generic DBIO::Storage::DBI, and a schema always has a driver (ADR 0067). ' | ||||||||||||||||||||||||||||||||||||||||||
| 483 | . "Declare it with use DBIO 'Schema', -<driver> (for example -pg), or with " | ||||||||||||||||||||||||||||||||||||||||||
| 484 | . "the driver's component (__PACKAGE__->load_components('PostgreSQL')) or " | ||||||||||||||||||||||||||||||||||||||||||
| 485 | . "storage_type (the driver's storage class, also on a clone before " | ||||||||||||||||||||||||||||||||||||||||||
| 486 | . 'connecting). DBIO->driver_for($dsn) names the driver of a DSN.' | ||||||||||||||||||||||||||||||||||||||||||
| 487 | . ( defined $hint ? " $hint" : '' ) | ||||||||||||||||||||||||||||||||||||||||||
| 488 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 15 | ▶ | sub _normalize_storage_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_storage_type: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 15 | my ($self, $storage_type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 15 | ▶ | if(ref $storage_type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 15 | return @$storage_type; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } elsif(ref $storage_type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | return %$storage_type; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | $self->throw_exception('Unsupported REFTYPE given: '. ref $storage_type); | |||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 56 | ▶ | sub register_storage_layer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_storage_layer: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 56 | my ($self, $layer) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 56 | ▶ | $self->throw_exception( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $layer and length $layer
MC/DC50%1/2
defined $layer and length $layer
defined $layer
length $layer
Truth table66%2/3
A and B
A= defined $layerB= length $layer
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 'register_storage_layer requires a storage layer class name' | ||||||||||||||||||||||||||||||||||||||||||
| 508 | ) unless defined $layer && length $layer; | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 55 | my @layers = @{ $self->storage_layers }; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 55 | ▶ | return $self if grep { $_ eq $layer } @layers; # dedup, preserve order | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | # NEW arrayref -- never push onto the shared inherited default in place. | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 54 | $self->storage_layers([ @layers, $layer ]); | |||||||||||||||||||||||||||||||||||||||||
| 515 | 54 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | # this might be oversimplified | ||||||||||||||||||||||||||||||||||||||||||
| 520 | # sub compose_namespace { | ||||||||||||||||||||||||||||||||||||||||||
| 521 | # my ($self, $target, $base) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | # my $schema = $self->clone; | ||||||||||||||||||||||||||||||||||||||||||
| 524 | # foreach my $source_name ($schema->sources) { | ||||||||||||||||||||||||||||||||||||||||||
| 525 | # my $source = $schema->source($source_name); | ||||||||||||||||||||||||||||||||||||||||||
| 526 | # my $target_class = "${target}::${source_name}"; | ||||||||||||||||||||||||||||||||||||||||||
| 527 | # $self->inject_base( | ||||||||||||||||||||||||||||||||||||||||||
| 528 | # $target_class => $source->result_class, ($base ? $base : ()) | ||||||||||||||||||||||||||||||||||||||||||
| 529 | # ); | ||||||||||||||||||||||||||||||||||||||||||
| 530 | # $source->result_class($target_class); | ||||||||||||||||||||||||||||||||||||||||||
| 531 | # $target_class->result_source_instance($source) | ||||||||||||||||||||||||||||||||||||||||||
| 532 | # if $target_class->can('result_source_instance'); | ||||||||||||||||||||||||||||||||||||||||||
| 533 | # $schema->register_source($source_name, $source); | ||||||||||||||||||||||||||||||||||||||||||
| 534 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | # return $schema; | ||||||||||||||||||||||||||||||||||||||||||
| 536 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 63 | ▶ | sub compose_namespace { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compose_namespace: called CC=8 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 63 | my ($self, $target, $base) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 63 | my $schema = $self->clone; | |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 63 | $schema->source_registrations({}); | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | # the original class-mappings must remain - otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 546 | # reverse_relationship_info will not work | ||||||||||||||||||||||||||||||||||||||||||
| 547 | #$schema->class_mappings({}); | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | { | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 316 | ▶ | no warnings qw/redefine/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 63 | ▶ | local *Class::C3::reinitialize = sub { } if old_mro; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 316 | ▶ | use warnings qw/redefine/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 63 | foreach my $source_name ($self->sources) { | |||||||||||||||||||||||||||||||||||||||||
| 555 | 2837 | my $orig_source = $self->source($source_name); | |||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 2837 | my $target_class = "${target}::${source_name}"; | |||||||||||||||||||||||||||||||||||||||||
| 558 | 2837 | ▶ | $self->inject_base($target_class, $orig_source->result_class, ($base || ()) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$base || ()
MC/DC0%0/2
$base || ()
$base
()
Truth table33%1/3
A || B
A= $baseB= ()
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | # register_source examines result_class, and then returns us a clone | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 2837 | my $new_source = $schema->register_source($source_name, bless | |||||||||||||||||||||||||||||||||||||||||
| 562 | { %$orig_source, result_class => $target_class }, | ||||||||||||||||||||||||||||||||||||||||||
| 563 | ref $orig_source, | ||||||||||||||||||||||||||||||||||||||||||
| 564 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 2837 | ▶ | if ($target_class->can('result_source_instance')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | # give the class a schema-less source copy | ||||||||||||||||||||||||||||||||||||||||||
| 568 | $target_class->result_source_instance( bless | ||||||||||||||||||||||||||||||||||||||||||
| 569 | { %$new_source, schema => ref $new_source->{schema} || $new_source->{schema} }, | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 2837 | ▶ | ref $new_source, | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $new_source->{'schema'} || $new_source->{'schema'}
MC/DC0%0/2
ref $new_source->{'schema'} || $new_source->{'schema'}
ref $new_source->{'schema'}
$new_source->{'schema'}
Truth table33%1/3
A || B
A= ref $new_source->{'schema'}B= $new_source->{'schema'}
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | quote_sub "${target}::${_}" => "shift->schema->$_(\@_)" | ||||||||||||||||||||||||||||||||||||||||||
| 576 | 63 | for qw(class source resultset); | |||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 63 | ▶ | Class::C3->reinitialize() if old_mro; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 63 | return $schema; | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | sub setup_connection_class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_connection_class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my ($class, $target, @info) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | $target->connection(@info); | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | sub svp_begin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svp_begin: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | ('svp_begin called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $self->storage->svp_begin($name); | |||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | sub svp_release { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svp_release: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | ('svp_release called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | $self->storage->svp_release($name); | |||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | sub svp_rollback { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
svp_rollback: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | $self->storage or $self->throw_exception | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | ('svp_rollback called on $schema without storage'); | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $self->storage->svp_rollback($name); | |||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 2910 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 2910 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | my $clone = { | ||||||||||||||||||||||||||||||||||||||||||
| 624 | (ref $self ? %$self : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 2910 | ▶ | (@_ == 1 && ref $_[0] eq 'HASH' ? %{ $_[0] } : @_), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 2910 | ▶ | bless $clone, (ref $self || $self); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 2910 | $clone->$_(undef) for qw/class_mappings source_registrations storage/; | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 2910 | $clone->_copy_state_from($self); | |||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 2910 | return $clone; | |||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | # Historically needed by external schema loaders - if you refactor, please | ||||||||||||||||||||||||||||||||||||||||||
| 637 | # make a compatibility shim | ||||||||||||||||||||||||||||||||||||||||||
| 638 | # -- Caelum | ||||||||||||||||||||||||||||||||||||||||||
| 639 | 2910 | ▶ | sub _copy_state_from { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_copy_state_from: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | 2910 | my ($self, $from) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | 2910 | $self->class_mappings({ %{$from->class_mappings} }); | |||||||||||||||||||||||||||||||||||||||||
| 643 | 2910 | $self->source_registrations({ %{$from->source_registrations} }); | |||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | 2910 | foreach my $source_name ($from->sources) { | |||||||||||||||||||||||||||||||||||||||||
| 646 | 90083 | my $source = $from->source($source_name); | |||||||||||||||||||||||||||||||||||||||||
| 647 | 90083 | my $new = $source->new($source); | |||||||||||||||||||||||||||||||||||||||||
| 648 | # we use extra here as we want to leave the class_mappings as they are | ||||||||||||||||||||||||||||||||||||||||||
| 649 | # but overwrite the source_registrations entry with the new source | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 90083 | $self->register_extra_source($source_name => $new); | |||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | 2910 | ▶ | if ($from->storage) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 8 | $self->storage($from->storage); | |||||||||||||||||||||||||||||||||||||||||
| 655 | 8 | $self->storage->set_schema($self); | |||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | 1414 | ▶ | sub throw_exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_exception: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | 1414 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 1414 | ▶ | if (my $act = $self->exception_action) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 17 | my $guard_disarmed; | |||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 17 | ▶ | my $guard = scope_guard { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 17 | ▶ | return if $guard_disarmed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 4 | local $SIG{__WARN__}; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 4 | DBIO::Util::masked_cluck(" | |||||||||||||||||||||||||||||||||||||||||
| 671 | !!! DBIO INTERNAL PANIC !!! | ||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | The exception_action() handler installed on '$self' | ||||||||||||||||||||||||||||||||||||||||||
| 674 | aborted the stacktrace below via a longjmp (either via Return::Multilevel or | ||||||||||||||||||||||||||||||||||||||||||
| 675 | plain goto, or Scope::Upper or something equally nefarious). There currently | ||||||||||||||||||||||||||||||||||||||||||
| 676 | is nothing safe DBIO can do, aside from displaying this error. A future | ||||||||||||||||||||||||||||||||||||||||||
| 677 | version ( 0.082900, when available ) will reduce the cases in which the | ||||||||||||||||||||||||||||||||||||||||||
| 678 | handler is invoked, but this is neither a complete solution, nor can it do | ||||||||||||||||||||||||||||||||||||||||||
| 679 | anything for other software that might be affected by a similar problem. | ||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | !!! FIX YOUR ERROR HANDLING !!! | ||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | This guard was activated beginning" | ||||||||||||||||||||||||||||||||||||||||||
| 684 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 685 | 17 | }; | |||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 688 | # if it throws - good, we'll go down to the do{} below | ||||||||||||||||||||||||||||||||||||||||||
| 689 | # if it doesn't - do different things depending on RV truthiness | ||||||||||||||||||||||||||||||||||||||||||
| 690 | 17 | ▶ | if( $act->(@args) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | $args[0] = ( | |||||||||||||||||||||||||||||||||||||||||
| 692 | "Invocation of the exception_action handler installed on $self did *not*" | ||||||||||||||||||||||||||||||||||||||||||
| 693 | .' result in an exception. DBIO is unable to function without a reliable' | ||||||||||||||||||||||||||||||||||||||||||
| 694 | .' exception mechanism, ensure that exception_action does not hide exceptions' | ||||||||||||||||||||||||||||||||||||||||||
| 695 | ." (original error: $args[0])" | ||||||||||||||||||||||||||||||||||||||||||
| 696 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||
| 698 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 2 | carp_unique ( | |||||||||||||||||||||||||||||||||||||||||
| 700 | "The exception_action handler installed on $self returned false instead" | ||||||||||||||||||||||||||||||||||||||||||
| 701 | .' of throwing an exception. This behavior has been deprecated, adjust your' | ||||||||||||||||||||||||||||||||||||||||||
| 702 | .' handler to always rethrow the supplied error' | ||||||||||||||||||||||||||||||||||||||||||
| 703 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 3 | $guard_disarmed = 1; | |||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | or | ||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | 17 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | # We call this to get the necessary warnings emitted and disregard the RV | ||||||||||||||||||||||||||||||||||||||||||
| 713 | # as it's definitely an exception if we got as far as this do{} block | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 10 | is_exception($@); | |||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 10 | $guard_disarmed = 1; | |||||||||||||||||||||||||||||||||||||||||
| 717 | 10 | $args[0] = $@; | |||||||||||||||||||||||||||||||||||||||||
| 718 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | # The trace masks the password the storage already holds, and asks nothing | ||||||||||||||||||||||||||||||||||||||||||
| 722 | # for it: no broker is called on this path. | ||||||||||||||||||||||||||||||||||||||||||
| 723 | 1410 | ▶ | my $storage = ref $self ? $self->storage : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | 1410 | ▶ | my $held = $storage && $storage->can('_held_connect_info') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$storage and $storage->can("_held_connect_info")
MC/DC50%1/2
$storage and $storage->can("_held_connect_info")
$storage
$storage->can("_held_connect_info")
Truth table66%2/3
A and B
A= $storageB= $storage->can("_held_connect_info")
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | ? $storage->_held_connect_info | ||||||||||||||||||||||||||||||||||||||||||
| 726 | : undef; | ||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | 1410 | DBIO::Exception->throw($args[0], $self->stacktrace, $held); | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 11 | ▶ | sub deploy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | 11 | my ($self, $sqltargs, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 11 | ▶ | $self->throw_exception("Can't deploy without storage") unless $self->storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | # Force driver determination before we look for a native Deploy class. | ||||||||||||||||||||||||||||||||||||||||||
| 737 | # A DSN-connected schema starts out holding the base DBIO::Storage::DBI | ||||||||||||||||||||||||||||||||||||||||||
| 738 | # here; the storage is only reblessed into the driver class (e.g. | ||||||||||||||||||||||||||||||||||||||||||
| 739 | # DBIO::SQLite::Storage) once it actually connects. Without this the | ||||||||||||||||||||||||||||||||||||||||||
| 740 | # dbio_deploy_class check below would always miss for the DSN path and | ||||||||||||||||||||||||||||||||||||||||||
| 741 | # fall through to the (unsupported) SQL::Translator codepath. | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 11 | $self->storage->ensure_connected; | |||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | # If the storage class advertises a native Deploy class | ||||||||||||||||||||||||||||||||||||||||||
| 745 | # (e.g. DBIO::PostgreSQL::Deploy), use it instead of the | ||||||||||||||||||||||||||||||||||||||||||
| 746 | # SQL::Translator codepath. The native classes know their database | ||||||||||||||||||||||||||||||||||||||||||
| 747 | # properly and avoid the lossy abstract-DDL roundtrip. | ||||||||||||||||||||||||||||||||||||||||||
| 748 | 11 | ▶ | if ($self->storage->can('dbio_deploy_class') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->storage->can("dbio_deploy_class") and my $deploy_class = $self->storage->dbio_deploy_class
MC/DC0%0/2
$self->storage->can("dbio_deploy_class") and my $deploy_class = $self->storage->dbio_deploy_class
$self->storage->can("dbio_deploy_class")
my $deploy_class = $self->storage->dbio_deploy_class
Truth table33%1/3
A and B
A= $self->storage->can("dbio_deploy_class")B= my $deploy_class = $self->storage->dbio_deploy_class
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | and my $deploy_class = $self->storage->dbio_deploy_class) { | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 11 | DBIO::Util::assert_class_name($deploy_class); | |||||||||||||||||||||||||||||||||||||||||
| 751 | 11 | ▶ | eval "require $deploy_class; 1" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | or $self->throw_exception("Cannot load $deploy_class: $@"); | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 11 | return $deploy_class->new( | |||||||||||||||||||||||||||||||||||||||||
| 754 | schema => $self, DBIO::Deploy::Base->deploy_args($sqltargs), | ||||||||||||||||||||||||||||||||||||||||||
| 755 | )->install; | ||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | $self->storage->deploy($self, undef, $sqltargs, $dir); | |||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 5 | ▶ | sub deployment_statements { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deployment_statements: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 5 | ▶ | $self->throw_exception("Can't generate deployment statements without a storage") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | if not $self->storage; | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 5 | $self->storage->deployment_statements($self, @_); | |||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | ▶ | sub create_ddl_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_ddl_dir: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | ▶ | $self->throw_exception("Can't create_ddl_dir without storage") unless $self->storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | $self->storage->create_ddl_dir($self, @_); | |||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||
| 780 | 8 | ▶ | sub ddl_filename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ddl_filename: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 8 | my ($self, $type, $version, $dir, $preversion) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 8 | ▶ | $version = "$preversion-$version" if $preversion; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | 8 | ▶ | my $class = blessed($self) || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($self) || $self
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self)
$self
Truth table33%1/3
A || B
A= builtin::blessed($self)B= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | 8 | $class =~ s/::/-/g; | |||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | 8 | return file_path($dir, "$class-$version-$type.sql"); | |||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 6 | ▶ | sub thaw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
thaw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | 6 | my ($self, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 794 | 6 | local $DBIO::ResultSource::thaw_schema = $self; | |||||||||||||||||||||||||||||||||||||||||
| 795 | 6 | return Storable::thaw($obj); | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | 6 | ▶ | sub freeze { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
freeze: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | 6 | return Storable::nfreeze($_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 7 | ▶ | sub dclone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dclone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 7 | my ($self, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 806 | 7 | local $DBIO::ResultSource::thaw_schema = $self; | |||||||||||||||||||||||||||||||||||||||||
| 807 | 7 | return Storable::dclone($obj); | |||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | 21 | ▶ | sub schema_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema_version: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 21 | ▶ | my $class = ref($self)||$self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | # does -not- use $schema->VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 816 | # since that varies in results depending on if version.pm is installed, and if | ||||||||||||||||||||||||||||||||||||||||||
| 817 | # so the perl or XS versions. If you want this to change, bug the version.pm | ||||||||||||||||||||||||||||||||||||||||||
| 818 | # author to make vpp and vxs behave the same. | ||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||
| 820 | 21 | my $version; | |||||||||||||||||||||||||||||||||||||||||
| 821 | { | ||||||||||||||||||||||||||||||||||||||||||
| 822 | 316 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 823 | 21 | $version = ${"${class}::VERSION"}; | |||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||
| 825 | 21 | return $version; | |||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 12538 | ▶ | sub register_class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 12538 | my ($self, $source_name, $to_register) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 12538 | $self->register_source($source_name => $to_register->result_source_instance); | |||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||
| 836 | 15380 | ▶ | sub register_source { shift->_register_source(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_source: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | ▶ | sub unregister_source { shift->_unregister_source(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unregister_source: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | 90185 | ▶ | sub register_extra_source { shift->_register_source(@_, { extra => 1 }) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_extra_source: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||
| 844 | 105565 | ▶ | sub _register_source { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_source: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 845 | 105565 | my ($self, $source_name, $source, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | 105565 | $source = $source->new({ %$source, source_name => $source_name }); | |||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 105565 | $source->schema($self); | |||||||||||||||||||||||||||||||||||||||||
| 850 | 105565 | ▶ | weaken $source->{schema} if ref($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | 105565 | my %reg = %{$self->source_registrations}; | |||||||||||||||||||||||||||||||||||||||||
| 853 | 105565 | $reg{$source_name} = $source; | |||||||||||||||||||||||||||||||||||||||||
| 854 | 105565 | $self->source_registrations(\%reg); | |||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | 105565 | ▶ | return $source if $params->{extra}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 15380 | my $rs_class = $source->result_class; | |||||||||||||||||||||||||||||||||||||||||
| 859 | 15380 | ▶ | if ($rs_class and my $rsrc = try { $rs_class->result_source_instance } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
$rs_class and my $rsrc = &try(sub {
$rs_class->result_source_instance;
}
)
MC/DC50%1/2
$rs_class and my $rsrc = &try(sub {
$rs_class->result_source_instance;
}
)
$rs_class
my $rsrc = &try(sub {
$rs_class->result_source_instance;
}
)
Truth table66%2/3
A and B
A= $rs_classB= my $rsrc = &try(sub {
$rs_class->result_source_instance;
}
)
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | 15377 | my %map = %{$self->class_mappings}; | |||||||||||||||||||||||||||||||||||||||||
| 861 | 15377 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
exists $map{$rs_class} and $map{$rs_class} ne $source_name and $rsrc ne $_[2]
exists $map{$rs_class} and $map{$rs_class} ne $source_name
MC/DC100%3/3
exists $map{$rs_class} and $map{$rs_class} ne $source_name and $rsrc ne $_[2]
exists $map{$rs_class}
$map{$rs_class} ne $source_name
$rsrc ne $_[2]
Truth table100%4/4
A and B and C
A= exists $map{$rs_class}B= $map{$rs_class} ne $source_nameC= $rsrc ne $_[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 862 | exists $map{$rs_class} | ||||||||||||||||||||||||||||||||||||||||||
| 863 | and | ||||||||||||||||||||||||||||||||||||||||||
| 864 | $map{$rs_class} ne $source_name | ||||||||||||||||||||||||||||||||||||||||||
| 865 | and | ||||||||||||||||||||||||||||||||||||||||||
| 866 | $rsrc ne $_[2] # orig_source | ||||||||||||||||||||||||||||||||||||||||||
| 867 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 868 | 1 | carp | |||||||||||||||||||||||||||||||||||||||||
| 869 | "$rs_class already had a registered source which was replaced by this call. " | ||||||||||||||||||||||||||||||||||||||||||
| 870 | . 'Perhaps you wanted register_extra_source(), though it is more likely you did ' | ||||||||||||||||||||||||||||||||||||||||||
| 871 | . 'something wrong.' | ||||||||||||||||||||||||||||||||||||||||||
| 872 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | 15377 | $map{$rs_class} = $source_name; | |||||||||||||||||||||||||||||||||||||||||
| 876 | 15377 | $self->class_mappings(\%map); | |||||||||||||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||
| 879 | 15380 | return $source; | |||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||
| 883 | 5 | ▶ | sub skill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skill: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 884 | 5 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 885 | 5 | my $want = DBIO::Skills->canonical_name($name); | |||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||
| 887 | 5 | ▶ | if (my $overrides = $self->skills) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | 5 | for my $key (keys %$overrides) { | |||||||||||||||||||||||||||||||||||||||||
| 889 | 7 | ▶ | return $overrides->{$key} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | if DBIO::Skills->canonical_name($key) eq $want; | ||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | # Make sure this schema's own driver dist is exposed, then resolve. | ||||||||||||||||||||||||||||||||||||||||||
| 895 | 1 | ▶ | DBIO::Skills->register_class(ref $self->storage) if $self->storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||
| 897 | 1 | return DBIO::Skills->skill($name); | |||||||||||||||||||||||||||||||||||||||||
| 898 | } | ||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | 316 | my $global_phase_destroy; | |||||||||||||||||||||||||||||||||||||||||
| 901 | 2683 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=7 SCAR=20.5
| |||||||||||||||||||||||||||||||||||||||||||
| 902 | ### NO detected_reinvoked_destructor check | ||||||||||||||||||||||||||||||||||||||||||
| 903 | ### This code very much relies on being called multuple times | ||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||
| 905 | 2683 | ▶ | return if $global_phase_destroy ||= in_global_destruction; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$global_phase_destroy ||= &in_global_destruction()
MC/DC0%0/2
$global_phase_destroy ||= &in_global_destruction()
$global_phase_destroy
&in_global_destruction()
Truth table33%1/3
A ||= B
A= $global_phase_destroyB= &in_global_destruction()
| |||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | 2683 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 908 | 2683 | my $srcs = $self->source_registrations; | |||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||
| 910 | 2683 | for my $source_name (keys %$srcs) { | |||||||||||||||||||||||||||||||||||||||||
| 911 | # find first source that is not about to be GCed (someone other than $self | ||||||||||||||||||||||||||||||||||||||||||
| 912 | # holds a reference to it) and reattach to it, weakening our own link | ||||||||||||||||||||||||||||||||||||||||||
| 913 | # | ||||||||||||||||||||||||||||||||||||||||||
| 914 | # during global destruction (if we have not yet bailed out) this should throw | ||||||||||||||||||||||||||||||||||||||||||
| 915 | # which will serve as a signal to not try doing anything else | ||||||||||||||||||||||||||||||||||||||||||
| 916 | # however beware - on older perls the exception seems randomly untrappable | ||||||||||||||||||||||||||||||||||||||||||
| 917 | # due to some weird race condition during thread joining :((( | ||||||||||||||||||||||||||||||||||||||||||
| 918 | 85502 | ▶ | if (length ref $srcs->{$source_name} and refcount($srcs->{$source_name}) > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length ref $srcs->{$source_name} and &refcount($srcs->{$source_name}) > 1
MC/DC50%1/2
length ref $srcs->{$source_name} and &refcount($srcs->{$source_name}) > 1
length ref $srcs->{$source_name}
&refcount($srcs->{$source_name}) > 1
Truth table66%2/3
A and B
A= length ref $srcs->{$source_name}B= &refcount($srcs->{$source_name}) > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 29 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 920 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 921 | 29 | $srcs->{$source_name}->schema($self); | |||||||||||||||||||||||||||||||||||||||||
| 922 | 29 | weaken $srcs->{$source_name}; | |||||||||||||||||||||||||||||||||||||||||
| 923 | 29 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 924 | 29 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | $global_phase_destroy = 1; | |||||||||||||||||||||||||||||||||||||||||
| 926 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | 29 | last; | |||||||||||||||||||||||||||||||||||||||||
| 929 | } | ||||||||||||||||||||||||||||||||||||||||||
| 930 | } | ||||||||||||||||||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||
| 933 | 1 | ▶ | sub _unregister_source { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unregister_source: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 934 | 1 | my ($self, $source_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 935 | 1 | my %reg = %{$self->source_registrations}; | |||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||
| 937 | 1 | my $source = delete $reg{$source_name}; | |||||||||||||||||||||||||||||||||||||||||
| 938 | 1 | $self->source_registrations(\%reg); | |||||||||||||||||||||||||||||||||||||||||
| 939 | 1 | ▶ | if ($source->result_class) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 940 | 1 | my %map = %{$self->class_mappings}; | |||||||||||||||||||||||||||||||||||||||||
| 941 | 1 | delete $map{$source->result_class}; | |||||||||||||||||||||||||||||||||||||||||
| 942 | 1 | $self->class_mappings(\%map); | |||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||
| 948 | 316 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | __END__ | ||||||||||||||||||||||||||||||||||||||||||