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