| 1 | 8 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Class::Scaffold::Environment; | ||||||||||||||||||||||||||||
| 6 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | $Class::Scaffold::Environment::VERSION = '1.102280'; | |||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Base class for framework environment classes | ||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Error::Hierarchy::Util 'load_class'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Class::Scaffold::Factory::Type; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Property::Lookup; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Data::Storage; # for AutoPrereq | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use parent 'Class::Scaffold::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 8 | Class::Scaffold::Base->add_autoloaded_package('Class::Scaffold::'); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # ptags: /(\bconst\b[ \t]+(\w+))/ | ||||||||||||||||||||||||||||
| 19 | 8 | __PACKAGE__->mk_scalar_accessors(qw(test_mode context)) | |||||||||||||||||||||||||||
| 20 | ->mk_boolean_accessors(qw(rollback_mode)) | ||||||||||||||||||||||||||||
| 21 | ->mk_class_hash_accessors(qw(storage_cache multiplex_transaction_omit)) | ||||||||||||||||||||||||||||
| 22 | ->mk_object_accessors( | ||||||||||||||||||||||||||||
| 23 | 'Property::Lookup' => { | ||||||||||||||||||||||||||||
| 24 | slot => 'configurator', | ||||||||||||||||||||||||||||
| 25 | comp_mthds => [ | ||||||||||||||||||||||||||||
| 26 | qw( | ||||||||||||||||||||||||||||
| 27 | get_config | ||||||||||||||||||||||||||||
| 28 | core_storage_name | ||||||||||||||||||||||||||||
| 29 | core_storage_args | ||||||||||||||||||||||||||||
| 30 | memory_storage_name | ||||||||||||||||||||||||||||
| 31 | ) | ||||||||||||||||||||||||||||
| 32 | ] | ||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | 8 | ▶ | use constant DEFAULTS => | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 36 | 8 | ▶ | (test_mode => (defined $ENV{TEST_MODE} && $ENV{TEST_MODE} == 1),); | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $ENV{'TEST_MODE'} && $ENV{'TEST_MODE'} == 1
MC/DC0%0/2
defined $ENV{'TEST_MODE'} && $ENV{'TEST_MODE'} == 1
defined $ENV{'TEST_MODE'}
$ENV{'TEST_MODE'} == 1
Truth table33%1/3
A && B
A= defined $ENV{'TEST_MODE'}B= $ENV{'TEST_MODE'} == 1
| |||||||||||||||||||||||||||||
| 37 | 8 | Class::Scaffold::Factory::Type->register_factory_type( | |||||||||||||||||||||||||||
| 38 | exception_container => 'Class::Scaffold::Exception::Container', | ||||||||||||||||||||||||||||
| 39 | result => 'Data::Storage::DBI::Result', | ||||||||||||||||||||||||||||
| 40 | storage_statement => 'Data::Storage::Statement', | ||||||||||||||||||||||||||||
| 41 | test_util_loader => 'Class::Scaffold::Test::UtilLoader', | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | { # closure over $env so that it really is private | ||||||||||||||||||||||||||||
| 44 | 8 | my $env; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub getenv { $env } | ||||||||||||||||||||||||||
|
Subroutine
getenv: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub setenv { | ||||||||||||||||||||||||||
|
Subroutine
setenv: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | my ($self, $newenv, @args) = @_; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $env = $newenv | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $newenv and UNIVERSAL::isa($newenv, "Class::Scaffold::Environment")
MC/DC0%0/2
ref $newenv and UNIVERSAL::isa($newenv, "Class::Scaffold::Environment")
ref $newenv
UNIVERSAL::isa($newenv, "Class::Scaffold::Environment")
Truth table0%0/3
A and B
A= ref $newenvB= UNIVERSAL::isa($newenv, "Class::Scaffold::Environment")
| |||||||||||||||||||||||||||||
| 50 | if ref $newenv | ||||||||||||||||||||||||||||
| 51 | && UNIVERSAL::isa($newenv, 'Class::Scaffold::Environment'); | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | unless (ref $newenv) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # it's a string containing the class name | ||||||||||||||||||||||||||||
| 55 | 0 | load_class $newenv, 1; | |||||||||||||||||||||||||||
| 56 | 0 | return $env = $newenv->new(@args); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | throw Error::Hierarchy::Internal::CustomMessage( | ||||||||||||||||||||||||||||
| 59 | 0 | custom_message => "Invalid environment specification [$newenv]",); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } # end of closure | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 8 | ▶ | sub setup { | ||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 0 | $self->configurator->default_layer->hash( | |||||||||||||||||||||||||||
| 66 | $self->every_hash('CONFIGURATOR_DEFAULTS')); | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 70 | # class name-related code | ||||||||||||||||||||||||||||
| 71 | 8 | ▶ | use constant STORAGE_CLASS_NAME_HASH => ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # storage names | ||||||||||||||||||||||||||||
| 74 | STG_NULL => 'Data::Storage::Null', | ||||||||||||||||||||||||||||
| 75 | STG_NULL_DBI => 'Data::Storage::DBI', # for testing | ||||||||||||||||||||||||||||
| 76 | 8 | ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub make_obj { | ||||||||||||||||||||||||||
|
Subroutine
make_obj: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | 0 | Class::Scaffold::Factory::Type->make_object_for_type(@_); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub get_class_name_for { | ||||||||||||||||||||||||||
|
Subroutine
get_class_name_for: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | my ($self, $object_type) = @_; | |||||||||||||||||||||||||||
| 85 | 0 | Class::Scaffold::Factory::Type->get_factory_class($object_type); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub isa_type { | ||||||||||||||||||||||||||
|
Subroutine
isa_type: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | my ($self, $object, $object_type) = @_; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | return unless UNIVERSAL::can($object, 'get_my_factory_type'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | my $factory_type = $object->get_my_factory_type; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | defined $factory_type ? $factory_type eq $object_type : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 8 | ▶ | sub gen_class_hash_accessor (@) { | ||||||||||||||||||||||||||
|
Subroutine
gen_class_hash_accessor: called CC=5 SCAR=25.5
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 8 | for my $prefix (@_) { | |||||||||||||||||||||||||||
| 97 | 8 | my $method = sprintf 'get_%s_class_name_for' => lc $prefix; | |||||||||||||||||||||||||||
| 98 | 8 | my $every_hash_name = sprintf '%s_CLASS_NAME_HASH', $prefix; | |||||||||||||||||||||||||||
| 99 | 8 | my $hash; # will be cached here | |||||||||||||||||||||||||||
| 100 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 8 | ▶ | $::PTAGS && $::PTAGS->add_tag($method, __FILE__, __LINE__ + 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | *$method = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | local $DB::sub = local *__ANON__ = sprintf "%s::%s", __PACKAGE__, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined &DB::DB and not $Devel::DProf::VERSION
MC/DC0%0/2
defined &DB::DB and not $Devel::DProf::VERSION
defined &DB::DB
not $Devel::DProf::VERSION
Truth table0%0/3
A and not(B)
A= defined &DB::DBB= not $Devel::DProf::VERSION
| |||||||||||||||||||||||||||||
| 104 | $method | ||||||||||||||||||||||||||||
| 105 | if defined &DB::DB && !$Devel::DProf::VERSION; | ||||||||||||||||||||||||||||
| 106 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | $hash ||= $self->every_hash($every_hash_name); | ||||||||||||||||||||||||||
|
Condition0%0/3
$hash ||= $self->every_hash($every_hash_name)
MC/DC0%0/2
$hash ||= $self->every_hash($every_hash_name)
$hash
$self->every_hash($every_hash_name)
Truth table0%0/3
A ||= B
A= $hashB= $self->every_hash($every_hash_name)
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $hash->{$key} || $hash->{_AUTO}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 8 | }; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # so FOO_CLASS_NAME() will return the whole every_hash | ||||||||||||||||||||||||||||
| 112 | 8 | $method = sprintf '%s_CLASS_NAME' => lc $prefix; | |||||||||||||||||||||||||||
| 113 | 8 | ▶ | $::PTAGS && $::PTAGS->add_tag($method, __FILE__, __LINE__ + 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | *$method = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | local $DB::sub = local *__ANON__ = sprintf "%s::%s", __PACKAGE__, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined &DB::DB and not $Devel::DProf::VERSION
MC/DC0%0/2
defined &DB::DB and not $Devel::DProf::VERSION
defined &DB::DB
not $Devel::DProf::VERSION
Truth table0%0/3
A and not(B)
A= defined &DB::DBB= not $Devel::DProf::VERSION
| |||||||||||||||||||||||||||||
| 116 | $method | ||||||||||||||||||||||||||||
| 117 | if defined &DB::DB && !$Devel::DProf::VERSION; | ||||||||||||||||||||||||||||
| 118 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | $hash ||= $self->every_hash($every_hash_name); | ||||||||||||||||||||||||||
|
Condition0%0/3
$hash ||= $self->every_hash($every_hash_name)
MC/DC0%0/2
$hash ||= $self->every_hash($every_hash_name)
$hash
$self->every_hash($every_hash_name)
Truth table0%0/3
A ||= B
A= $hashB= $self->every_hash($every_hash_name)
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | wantarray ? %$hash : $hash; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 8 | }; | |||||||||||||||||||||||||||
| 122 | 8 | $method = sprintf 'release_%s_class_name_hash' => lc $prefix; | |||||||||||||||||||||||||||
| 123 | 8 | ▶ | $::PTAGS && $::PTAGS->add_tag($method, __FILE__, __LINE__ + 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | *$method = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | local $DB::sub = local *__ANON__ = sprintf "%s::%s", __PACKAGE__, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined &DB::DB and not $Devel::DProf::VERSION
MC/DC0%0/2
defined &DB::DB and not $Devel::DProf::VERSION
defined &DB::DB
not $Devel::DProf::VERSION
Truth table0%0/3
A and not(B)
A= defined &DB::DBB= not $Devel::DProf::VERSION
| |||||||||||||||||||||||||||||
| 126 | $method | ||||||||||||||||||||||||||||
| 127 | if defined &DB::DB && !$Devel::DProf::VERSION; | ||||||||||||||||||||||||||||
| 128 | 0 | undef $hash; | |||||||||||||||||||||||||||
| 129 | 8 | }; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 8 | gen_class_hash_accessor('STORAGE'); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub load_cached_class_for_type { | ||||||||||||||||||||||||||
|
Subroutine
load_cached_class_for_type: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 0 | my ($self, $object_type_const) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # Cache for efficiency reasons; the environment is the core of the whole | ||||||||||||||||||||||||||||
| 138 | # framework. | ||||||||||||||||||||||||||||
| 139 | 0 | our %cache; | |||||||||||||||||||||||||||
| 140 | 0 | my $class = $self->get_class_name_for($object_type_const); | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | unless (defined($class) && length($class)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $class and length $class
MC/DC0%0/2
defined $class and length $class
defined $class
length $class
Truth table0%0/3
A and B
A= defined $classB= length $class
| |||||||||||||||||||||||||||||
| 142 | 0 | throw Error::Hierarchy::Internal::CustomMessage(custom_message => | |||||||||||||||||||||||||||
| 143 | "Can't find class for object type [$object_type_const]",); | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 0 | load_class $class, $self->test_mode; | |||||||||||||||||||||||||||
| 146 | 0 | $class; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub storage_for_type { | ||||||||||||||||||||||||||
|
Subroutine
storage_for_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 0 | my ($self, $object_type) = @_; | |||||||||||||||||||||||||||
| 151 | 0 | my $storage_type = $self->get_storage_type_for($object_type); | |||||||||||||||||||||||||||
| 152 | 0 | $self->$storage_type; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # When running class tests in non-final distributions, which storage should we | ||||||||||||||||||||||||||||
| 156 | # use? Ideally, every distribution (but especially the non-final ones like | ||||||||||||||||||||||||||||
| 157 | # Registry-Core and Registry-Enum) should have a mock storage against which to | ||||||||||||||||||||||||||||
| 158 | # test. Until then, the following mechanism can be used: | ||||||||||||||||||||||||||||
| 159 | # | ||||||||||||||||||||||||||||
| 160 | # Every storage notes whether it is abstract or an implementation. Class tests | ||||||||||||||||||||||||||||
| 161 | # that need a storage will skip() the tests if the storage is abstract. | ||||||||||||||||||||||||||||
| 162 | # Problem: we need to ask all the object types' storages used in a test code | ||||||||||||||||||||||||||||
| 163 | # block, as different objects types could use different storages. For example: | ||||||||||||||||||||||||||||
| 164 | # skip(...) unless | ||||||||||||||||||||||||||||
| 165 | # $self->delegate->all_storages_are_implemented(qw/person command .../); | ||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub all_storages_are_implemented { | ||||||||||||||||||||||||||
|
Subroutine
all_storages_are_implemented: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 0 | my ($self, @object_types) = @_; | |||||||||||||||||||||||||||
| 168 | 0 | for my $object_type (@object_types) { | |||||||||||||||||||||||||||
| 169 | 0 | ▶ | return 0 if $self->storage_for_type($object_type)->is_abstract; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 0 | 1; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # Have a special method for making delegate objects, because delegates will be | ||||||||||||||||||||||||||||
| 175 | # cached (i.e., pseudo-singletons) and don't need storages and extra args and | ||||||||||||||||||||||||||||
| 176 | # such. | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub make_delegate { | ||||||||||||||||||||||||||
|
Subroutine
make_delegate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 0 | my ($self, $object_type_const, @args) = @_; | |||||||||||||||||||||||||||
| 179 | 0 | our %cache; | |||||||||||||||||||||||||||
| 180 | 0 | ▶ | $cache{delegate}{$object_type_const} ||= | ||||||||||||||||||||||||||
|
Condition0%0/3
$Class::Scaffold::Environment::cache{"delegate"}{$object_type_const} ||= $self->make_obj($object_type_const, @args)
MC/DC0%0/2
$Class::Scaffold::Environment::cache{"delegate"}{$object_type_const} ||= $self->make_obj($object_type_const, @args)
$Class::Scaffold::Environment::cache{"delegate"}{$object_type_const}
$self->make_obj($object_type_const, @args)
Truth table0%0/3
A ||= B
A= $Class::Scaffold::Environment::cache{"delegate"}{$object_type_const}B= $self->make_obj($object_type_const, @args)
| |||||||||||||||||||||||||||||
| 181 | $self->make_obj($object_type_const, @args); | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 185 | # storage-related code | ||||||||||||||||||||||||||||
| 186 | 8 | ▶ | use constant STORAGE_TYPE_HASH => (_AUTO => 'core_storage',); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub get_storage_type_for { | ||||||||||||||||||||||||||
|
Subroutine
get_storage_type_for: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 190 | 0 | our %cache; | |||||||||||||||||||||||||||
| 191 | return $cache{get_storage_type_for}{$key} | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if exists $cache{get_storage_type_for}{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | my $storage_type_for = $self->every_hash('STORAGE_TYPE_HASH'); | |||||||||||||||||||||||||||
| 194 | $cache{get_storage_type_for}{$key} = $storage_type_for->{$key} | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | || $storage_type_for->{_AUTO}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$storage_type_for->{$key} || $storage_type_for->{'_AUTO'}
MC/DC0%0/2
$storage_type_for->{$key} || $storage_type_for->{'_AUTO'}
$storage_type_for->{$key}
$storage_type_for->{'_AUTO'}
Truth table0%0/3
A || B
A= $storage_type_for->{$key}B= $storage_type_for->{'_AUTO'}
| |||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub make_storage_object { | ||||||||||||||||||||||||||
|
Subroutine
make_storage_object: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 200 | 0 | my $storage_name = shift; | |||||||||||||||||||||||||||
| 201 | my %args = | ||||||||||||||||||||||||||||
| 202 | @_ == 1 | ||||||||||||||||||||||||||||
| 203 | ? defined $_[0] | ||||||||||||||||||||||||||||
| 204 | ? ref $_[0] eq 'HASH' | ||||||||||||||||||||||||||||
| 205 | 0 | ▶ | ? %{ $_[0] } | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 206 | : @_ | ||||||||||||||||||||||||||||
| 207 | : () | ||||||||||||||||||||||||||||
| 208 | : @_; | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if (my $class = $self->get_storage_class_name_for($storage_name)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | load_class $class, $self->test_mode; | |||||||||||||||||||||||||||
| 211 | 0 | return $class->new(%args); | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | throw Error::Hierarchy::Internal::CustomMessage( | ||||||||||||||||||||||||||||
| 214 | 0 | custom_message => "Invalid storage name [$storage_name]",); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub core_storage { | ||||||||||||||||||||||||||
|
Subroutine
core_storage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 218 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 219 | $self->storage_cache->{core_storage} ||= | ||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $self->make_storage_object($self->core_storage_name, | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->storage_cache->{"core_storage"} ||= $self->make_storage_object($self->core_storage_name, $self->core_storage_args)
MC/DC0%0/2
$self->storage_cache->{"core_storage"} ||= $self->make_storage_object($self->core_storage_name, $self->core_storage_args)
$self->storage_cache->{"core_storage"}
$self->make_storage_object($self->core_storage_name, $self->core_storage_args)
Truth table0%0/3
A ||= B
A= $self->storage_cache->{"core_storage"}B= $self->make_storage_object($self->core_storage_name, $self->core_storage_args)
| |||||||||||||||||||||||||||||
| 221 | $self->core_storage_args); | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub memory_storage { | ||||||||||||||||||||||||||
|
Subroutine
memory_storage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 226 | $self->storage_cache->{memory_storage} ||= | ||||||||||||||||||||||||||||
| 227 | 0 | ▶ | $self->make_storage_object($self->memory_storage_name); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->storage_cache->{"memory_storage"} ||= $self->make_storage_object($self->memory_storage_name)
MC/DC0%0/2
$self->storage_cache->{"memory_storage"} ||= $self->make_storage_object($self->memory_storage_name)
$self->storage_cache->{"memory_storage"}
$self->make_storage_object($self->memory_storage_name)
Truth table0%0/3
A ||= B
A= $self->storage_cache->{"memory_storage"}B= $self->make_storage_object($self->memory_storage_name)
| |||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # Forward some special methods onto all cached storages. Some storages could | ||||||||||||||||||||||||||||
| 231 | # be a bit special - we don't want to rollback or disconnect from them when | ||||||||||||||||||||||||||||
| 232 | # calling the multiplexing rollback() and disconnect() methods below, so we | ||||||||||||||||||||||||||||
| 233 | # ignore them when multiplexing. For example, mutex storages (see | ||||||||||||||||||||||||||||
| 234 | # Data-Conveyor for the concept). | ||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub rollback { | ||||||||||||||||||||||||||
|
Subroutine
rollback: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 236 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 237 | 0 | ▶ | while (my ($storage_type, $storage) = each %{ $self->storage_cache }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | next if $self->multiplex_transaction_omit($storage_type); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 0 | $storage->rollback; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub commit { | ||||||||||||||||||||||||||
|
Subroutine
commit: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 244 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 245 | 0 | ▶ | while (my ($storage_type, $storage) = each %{ $self->storage_cache }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | next if $self->multiplex_transaction_omit($storage_type); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 0 | $storage->commit; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub disconnect { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 253 | 0 | ▶ | while (my ($storage_type, $storage) = each %{ $self->storage_cache }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | next if $self->multiplex_transaction_omit($storage_type); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | $storage->disconnect; | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | # remove it from the cache so we'll reconnect next time | ||||||||||||||||||||||||||||
| 258 | 0 | $self->storage_cache_delete($storage_type); | |||||||||||||||||||||||||||
| 259 | 0 | require Class::Scaffold::Storable; | |||||||||||||||||||||||||||
| 260 | 0 | %Class::Scaffold::Storable::cache = (); | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | 0 | our %cache; | |||||||||||||||||||||||||||
| 263 | 0 | $cache{get_storage_type_for} = {}; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # Check configuration values for consistency. Empty, but it exists so | ||||||||||||||||||||||||||||
| 267 | # subclasses can call SUPER::check() | ||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub check { } | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 269 | 8 | 1; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | __END__ | ||||||||||||||||||||||||||||