line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util::ExternalMeta; |
2
|
246
|
|
|
246
|
|
1713
|
use strict; |
|
246
|
|
|
|
|
479
|
|
|
246
|
|
|
|
|
6966
|
|
3
|
246
|
|
|
246
|
|
1194
|
use warnings; |
|
246
|
|
|
|
|
475
|
|
|
246
|
|
|
|
|
10340
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.302180'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
246
|
|
|
246
|
|
1389
|
use Carp qw/croak/; |
|
246
|
|
|
|
|
513
|
|
|
246
|
|
|
|
|
25534
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub META_KEY() { '_meta' } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw/meta set_meta get_meta delete_meta/; |
13
|
246
|
|
|
246
|
|
1752
|
BEGIN { require Exporter; our @ISA = qw(Exporter) } |
|
246
|
|
|
|
|
100447
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub set_meta { |
16
|
5
|
|
|
5
|
1
|
23
|
my $self = shift; |
17
|
5
|
|
|
|
|
15
|
my ($key, $value) = @_; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
24
|
validate_key($key); |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
50
|
|
|
32
|
$self->{+META_KEY} ||= {}; |
22
|
5
|
|
|
|
|
16
|
$self->{+META_KEY}->{$key} = $value; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_meta { |
26
|
315
|
|
|
315
|
1
|
571
|
my $self = shift; |
27
|
315
|
|
|
|
|
617
|
my ($key) = @_; |
28
|
|
|
|
|
|
|
|
29
|
315
|
|
|
|
|
762
|
validate_key($key); |
30
|
|
|
|
|
|
|
|
31
|
315
|
100
|
|
|
|
750
|
my $meta = $self->{+META_KEY} or return undef; |
32
|
309
|
|
|
|
|
928
|
return $meta->{$key}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub delete_meta { |
36
|
4
|
|
|
4
|
1
|
29
|
my $self = shift; |
37
|
4
|
|
|
|
|
18
|
my ($key) = @_; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
25
|
validate_key($key); |
40
|
|
|
|
|
|
|
|
41
|
2
|
50
|
|
|
|
10
|
my $meta = $self->{+META_KEY} or return undef; |
42
|
2
|
|
|
|
|
11
|
delete $meta->{$key}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub meta { |
46
|
2256
|
|
|
2256
|
1
|
4323
|
my $self = shift; |
47
|
2256
|
|
|
|
|
4730
|
my ($key, $default) = @_; |
48
|
|
|
|
|
|
|
|
49
|
2256
|
|
|
|
|
6597
|
validate_key($key); |
50
|
|
|
|
|
|
|
|
51
|
2254
|
|
|
|
|
4594
|
my $meta = $self->{+META_KEY}; |
52
|
2254
|
100
|
100
|
|
|
6597
|
return undef unless $meta || defined($default); |
53
|
|
|
|
|
|
|
|
54
|
2251
|
100
|
|
|
|
4810
|
unless($meta) { |
55
|
371
|
|
|
|
|
841
|
$meta = {}; |
56
|
371
|
|
|
|
|
984
|
$self->{+META_KEY} = $meta; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$meta->{$key} = $default |
60
|
2251
|
100
|
100
|
|
|
9125
|
if defined($default) && !defined($meta->{$key}); |
61
|
|
|
|
|
|
|
|
62
|
2251
|
|
|
|
|
6982
|
return $meta->{$key}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub validate_key { |
66
|
2580
|
|
|
2580
|
0
|
4044
|
my $key = shift; |
67
|
|
|
|
|
|
|
|
68
|
2580
|
100
|
66
|
|
|
12040
|
return if $key && !ref($key); |
69
|
|
|
|
|
|
|
|
70
|
4
|
100
|
|
|
|
25
|
my $render_key = defined($key) ? "'$key'" : 'undef'; |
71
|
4
|
|
|
|
|
526
|
croak "Invalid META key: $render_key, keys must be true, and may not be references"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |