| 1 | package OpenStack::MetaAPI::Helpers::DataAsYaml; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 21 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 21 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 21 | ▶ | use YAML::XS (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 21 | our $_CACHE; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | ## TODO: publish this to CPAN as its own module | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | ### FIXME publish as its own package | ||||||||||||||||||||
| 13 | ### and provide one import function which can old its own cache | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub LoadData { | ||||||||||||||||||||
| 16 | 17 | ▶ | my ($pkg) = @_; | ||||||||||||||||||
|
Subroutine
LoadData: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 17 | ▶ | $pkg //= (caller(0))[0]; | ||||||||||||||||||
|
Condition33%1/3
$pkg //= (caller 0)[0]
MC/DC0%0/2
$pkg //= (caller 0)[0]
$pkg
(caller 0)[0]
Truth table33%1/3
A //= B
A= $pkgB= (caller 0)[0]
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 17 | return LoadDataFrom($pkg); | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | sub LoadDataFrom { | ||||||||||||||||||||
| 24 | 66 | ▶ | my ($pkg) = @_; | ||||||||||||||||||
|
Subroutine
LoadDataFrom: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 66 | ▶ | die "undefined package" unless defined $pkg; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 65 | ▶ | $_CACHE //= {}; | ||||||||||||||||||
|
Condition100%2/2
$OpenStack::MetaAPI::Helpers::DataAsYaml::_CACHE //= {}
MC/DC100%1/1
$OpenStack::MetaAPI::Helpers::DataAsYaml::_CACHE //= {}
$OpenStack::MetaAPI::Helpers::DataAsYaml::_CACHE
Truth table100%2/2
A
A= $OpenStack::MetaAPI::Helpers::DataAsYaml::_CACHE
| |||||||||||||||||||||
| 29 | 65 | ▶ | return $_CACHE->{$pkg} if $_CACHE->{$pkg}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 52 | my $data; | |||||||||||||||||||
| 32 | { | ||||||||||||||||||||
| 33 | 52 | local $/; | |||||||||||||||||||
| 34 | 21 | ▶ | my $fh = do { no strict 'refs'; \*{"${pkg}::DATA"} }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 52 | $data = <$fh>; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 52 | ▶ | return unless defined $data; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 51 | $_CACHE->{$pkg} = YAML::XS::Load($data); | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 51 | return $_CACHE->{$pkg}; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | sub clear_cache { | ||||||||||||||||||||
| 46 | 3 | ▶ | $_CACHE = {}; | ||||||||||||||||||
|
Subroutine
clear_cache: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 21 | 1; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =pod | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =encoding UTF-8 | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =head1 NAME | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | OpenStack::MetaAPI::Helpers::DataAsYaml | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head1 VERSION | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | version 0.004 | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =head1 AUTHOR | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | Nicolas R <atoomic@cpan.org> | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | This software is copyright (c) 2019 by cPanel, Inc. | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 74 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||