MetaAPI/Helpers/DataAsYaml.pm

filter: Statementstmt 96.3% 26 / 27 Branchbran 50.0% 3 / 6 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 3 totaltotal 76.0% 38 / 50 CC 6 SCAR 11.5
CC
6
Cov
84%
LoadDataFrom
5.1
LoadData
2.1
clear_cache
2.0
CRAP 3.2
« MetaAPI/API/Network.pm ↑ Summary MetaAPI/API.pm »
1 package OpenStack::MetaAPI::Helpers::DataAsYaml;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 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 6 ▶ my ($pkg) = @_;
Subroutine LoadData: called CC=2 SCAR=7.6
Pod undocumented
17  
18 6 ▶ $pkg //= (caller(0))[0];
Condition33%1/3
$pkg //= (caller 0)[0]
l!l&&r!l&&!r
060
MC/DC0%0/2
$pkg //= (caller 0)[0]
$pkg (caller 0)[0]
Truth table33%1/3
A //= B
A= $pkgB= (caller 0)[0]
ABresult
1X1
011
000
19  
20 6 return LoadDataFrom($pkg);
21 }
22  
23 sub LoadDataFrom {
24 14 ▶ my ($pkg) = @_;
Subroutine LoadDataFrom: called CC=5 SCAR=16.3
Pod undocumented
25  
26 14 ▶ die "undefined package" unless defined $pkg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg 0 14 14
27  
28 14 ▶ $_CACHE //= {};
Condition100%2/2
$OpenStack::MetaAPI::Helpers::DataAsYaml::_CACHE //= {}
l!l
86
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
Aresult
11
00
29 14 ▶ return $_CACHE->{$pkg} if $_CACHE->{$pkg};
Branch: 1 branch
BranchTrueFalseTotal
if $OpenStack::MetaAPI::Helpers::DataAsYaml::_CACHE->{$pkg} 0 14 14
30  
31 14 my $data;
32 {
33 14 local $/;
34 14 my $fh = eval '\*' . $pkg . '::DATA';
35 14 $data = <$fh>;
36 }
37  
38 14 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 14 14
39  
40 14 $_CACHE->{$pkg} = YAML::XS::Load($data);
41  
42 14 return $_CACHE->{$pkg};
43 }
44  
45 sub clear_cache {
46 0 ▶ $_CACHE = {};
Subroutine clear_cache: not called CC=1 SCAR=6.9
Pod undocumented
47 }
48  
49 6 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.002
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
« MetaAPI/API/Network.pm ↑ Summary MetaAPI/API.pm »