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