line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenStack::MetaAPI::Helpers::DataAsYaml; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
43
|
use strict; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
185
|
|
4
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
136
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
30
|
use YAML::XS (); |
|
6
|
|
|
|
|
38
|
|
|
6
|
|
|
|
|
1421
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
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
|
|
|
6
|
0
|
42
|
my ($pkg) = @_; |
17
|
|
|
|
|
|
|
|
18
|
6
|
|
33
|
|
|
89
|
$pkg //= (caller(0))[0]; |
19
|
|
|
|
|
|
|
|
20
|
6
|
|
|
|
|
25
|
return LoadDataFrom($pkg); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub LoadDataFrom { |
24
|
14
|
|
|
14
|
0
|
36
|
my ($pkg) = @_; |
25
|
|
|
|
|
|
|
|
26
|
14
|
50
|
|
|
|
50
|
die "undefined package" unless defined $pkg; |
27
|
|
|
|
|
|
|
|
28
|
14
|
|
100
|
|
|
62
|
$_CACHE //= {}; |
29
|
14
|
50
|
|
|
|
48
|
return $_CACHE->{$pkg} if $_CACHE->{$pkg}; |
30
|
|
|
|
|
|
|
|
31
|
14
|
|
|
|
|
25
|
my $data; |
32
|
|
|
|
|
|
|
{ |
33
|
14
|
|
|
|
|
26
|
local $/; |
|
14
|
|
|
|
|
59
|
|
34
|
14
|
|
|
|
|
881
|
my $fh = eval '\*' . $pkg . '::DATA'; |
35
|
14
|
|
|
|
|
406
|
$data = <$fh>; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
14
|
50
|
|
|
|
74
|
return unless defined $data; |
39
|
|
|
|
|
|
|
|
40
|
14
|
|
|
|
|
2877
|
$_CACHE->{$pkg} = YAML::XS::Load($data); |
41
|
|
|
|
|
|
|
|
42
|
14
|
|
|
|
|
156
|
return $_CACHE->{$pkg}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub clear_cache { |
46
|
0
|
|
|
0
|
0
|
|
$_CACHE = {}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |