line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Attribute::Method::Tags::Registry; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
690
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $by_tag = {}; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub add { |
13
|
4
|
|
|
4
|
1
|
10
|
my ( undef, $class, $method, $tags ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
4
|
50
|
|
|
|
4
|
if ( not scalar @{ $tags } ) { |
|
4
|
|
|
|
|
11
|
|
16
|
0
|
|
|
|
|
0
|
die "no tags defined\n"; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
|
|
6
|
foreach my $tag ( @{ $tags } ) { |
|
4
|
|
|
|
|
7
|
|
20
|
5
|
50
|
|
|
|
28
|
if ( $tag !~ /^\w+$/ ) { |
21
|
0
|
|
|
|
|
0
|
die "tags must be alphanumeric\n"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# dedupe tags |
26
|
4
|
|
|
|
|
6
|
my %tags = map { $_ => 1 } @{ $tags }; |
|
5
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
8
|
|
27
|
|
|
|
|
|
|
|
28
|
7
|
100
|
|
|
|
35
|
my $exists = grep { |
29
|
4
|
|
|
|
|
12
|
exists $by_tag->{ $_ }{ $class } |
30
|
|
|
|
|
|
|
and exists $by_tag->{ $_ }{ $class }{ $method } |
31
|
|
|
|
|
|
|
} __PACKAGE__->tags; |
32
|
4
|
50
|
|
|
|
10
|
if ( $exists ) { |
33
|
0
|
|
|
|
|
0
|
die "tags for $class->$method already exists, method redefinition perhaps?\n"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
9
|
foreach my $tag ( keys %tags ) { |
37
|
5
|
|
|
|
|
22
|
$by_tag->{ $tag }{ $class }{ $method } = 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub tags { |
42
|
5
|
|
|
5
|
1
|
1064
|
return sort keys %{ $by_tag }; |
|
5
|
|
|
|
|
30
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub classes_with_tag { |
46
|
5
|
|
|
5
|
1
|
2471
|
my ( undef, $tag ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
5
|
100
|
|
|
|
207
|
croak( "no tag specified" ) if not defined $tag; |
49
|
|
|
|
|
|
|
|
50
|
4
|
100
|
|
|
|
18
|
return if not exists $by_tag->{ $tag }; |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
6
|
return sort keys %{ $by_tag->{ $tag } }; |
|
3
|
|
|
|
|
35
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub methods_with_tag { |
56
|
12
|
|
|
12
|
1
|
5786
|
my ( undef, $class, $tag ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
12
|
100
|
|
|
|
364
|
croak( "no class specified" ) if not defined $class; |
59
|
10
|
100
|
|
|
|
255
|
croak( "no tag specified" ) if not defined $tag; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# avoid auto-vivication |
62
|
8
|
100
|
|
|
|
19
|
return if not exists $by_tag->{ $tag }; |
63
|
|
|
|
|
|
|
|
64
|
6
|
|
|
|
|
7
|
return sort keys %{ $by_tag->{ $tag }{ $class } }; |
|
6
|
|
|
|
|
30
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub method_has_tag { |
68
|
9
|
|
|
9
|
1
|
5392
|
my ( undef, $class, $method, $tag ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
9
|
100
|
|
|
|
305
|
croak( "no class specified" ) if not defined $class; |
71
|
7
|
100
|
|
|
|
279
|
croak( "no method specified" ) if not defined $method; |
72
|
5
|
100
|
|
|
|
252
|
croak( "no tag specified" ) if not defined $tag; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# avoid auto-vivication |
75
|
3
|
50
|
|
|
|
9
|
return 0 if not exists $by_tag->{ $tag }; |
76
|
3
|
50
|
|
|
|
10
|
return 0 if not exists $by_tag->{ $tag }{ $class }; |
77
|
|
|
|
|
|
|
|
78
|
3
|
100
|
|
|
|
13
|
return exists $by_tag->{ $tag }{ $class }{ $method } |
79
|
|
|
|
|
|
|
? 1 |
80
|
|
|
|
|
|
|
: 0; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |