line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util::ExternalMeta; |
2
|
57
|
|
|
57
|
|
177
|
use strict; |
|
57
|
|
|
|
|
58
|
|
|
57
|
|
|
|
|
1213
|
|
3
|
57
|
|
|
57
|
|
165
|
use warnings; |
|
57
|
|
|
|
|
53
|
|
|
57
|
|
|
|
|
2067
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000043'; |
6
|
|
|
|
|
|
|
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) |
7
|
|
|
|
|
|
|
|
8
|
57
|
|
|
57
|
|
174
|
use Carp qw/croak/; |
|
57
|
|
|
|
|
66
|
|
|
57
|
|
|
|
|
3655
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub META_KEY() { '_meta' } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw/meta set_meta get_meta delete_meta/; |
13
|
57
|
|
|
57
|
|
212
|
use base 'Exporter'; |
|
57
|
|
|
|
|
66
|
|
|
57
|
|
|
|
|
17539
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub set_meta { |
16
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
17
|
2
|
|
|
|
|
3
|
my ($key, $value) = @_; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
5
|
validate_key($key); |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
50
|
|
|
10
|
$self->{+META_KEY} ||= {}; |
22
|
2
|
|
|
|
|
5
|
$self->{+META_KEY}->{$key} = $value; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_meta { |
26
|
6
|
|
|
6
|
1
|
20
|
my $self = shift; |
27
|
6
|
|
|
|
|
6
|
my ($key) = @_; |
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
|
|
11
|
validate_key($key); |
30
|
|
|
|
|
|
|
|
31
|
6
|
100
|
|
|
|
20
|
my $meta = $self->{+META_KEY} or return undef; |
32
|
2
|
|
|
|
|
6
|
return $meta->{$key}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub delete_meta { |
36
|
4
|
|
|
4
|
1
|
40
|
my $self = shift; |
37
|
4
|
|
|
|
|
9
|
my ($key) = @_; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
8
|
validate_key($key); |
40
|
|
|
|
|
|
|
|
41
|
2
|
50
|
|
|
|
6
|
my $meta = $self->{+META_KEY} or return undef; |
42
|
2
|
|
|
|
|
5
|
delete $meta->{$key}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub meta { |
46
|
19
|
|
|
19
|
1
|
58
|
my $self = shift; |
47
|
19
|
|
|
|
|
24
|
my ($key, $default) = @_; |
48
|
|
|
|
|
|
|
|
49
|
19
|
|
|
|
|
25
|
validate_key($key); |
50
|
|
|
|
|
|
|
|
51
|
17
|
|
|
|
|
18
|
my $meta = $self->{+META_KEY}; |
52
|
17
|
100
|
100
|
|
|
47
|
return undef unless $meta || defined($default); |
53
|
|
|
|
|
|
|
|
54
|
14
|
100
|
|
|
|
20
|
unless($meta) { |
55
|
1
|
|
|
|
|
2
|
$meta = {}; |
56
|
1
|
|
|
|
|
3
|
$self->{+META_KEY} = $meta; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$meta->{$key} = $default |
60
|
14
|
100
|
100
|
|
|
55
|
if defined($default) && !defined($meta->{$key}); |
61
|
|
|
|
|
|
|
|
62
|
14
|
|
|
|
|
36
|
return $meta->{$key}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub validate_key { |
66
|
31
|
|
|
31
|
0
|
27
|
my $key = shift; |
67
|
|
|
|
|
|
|
|
68
|
31
|
100
|
66
|
|
|
102
|
return if $key && !ref($key); |
69
|
|
|
|
|
|
|
|
70
|
4
|
100
|
|
|
|
10
|
my $render_key = defined($key) ? "'$key'" : 'undef'; |
71
|
4
|
|
|
|
|
348
|
croak "Invalid META key: $render_key, keys must be true, and may not be references"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |