Tags/Registry.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 82.1% 23 / 28 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 5 / 5 totaltotal 88.4% 84 / 95 CC 18 SCAR 16.8
CC
18
Cov
89%
add
8.0
method_has_tag
7.1
methods_with_tag
4.0
CRAP 5.4
↑ Summary Tags.pm »
1 package Attribute::Method::Tags::Registry;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.10';
9  
10 1 my $by_tag = {};
11  
12 4 ▶sub add {
Subroutine add: called CC=7 SCAR=20.7
Pod documented
13 4 my ( undef, $class, $method, $tags ) = @_;
14  
15 4 ▶ if ( not scalar @{ $tags } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$tags;}) 0 4 4
16 0 die "no tags defined\n";
17 }
18  
19 4 foreach my $tag ( @{ $tags } ) {
20 5 ▶ if ( $tag !~ /^\w+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tag =~ /^\w+$/) 0 5 5
21 0 die "tags must be alphanumeric\n";
22 }
23 }
24  
25 # dedupe tags
26 4 my %tags = map { $_ => 1 } @{ $tags };
27  
28 my $exists = grep {
29 4 exists $by_tag->{ $_ }{ $class }
30 7 ▶ and exists $by_tag->{ $_ }{ $class }{ $method }
Condition66%2/3
exists $by_tag->{$_}{$class} && exists $by_tag->{$_}{$class}{$method}
!ll&&!rl&&r
340
MC/DC0%0/2
exists $by_tag->{$_}{$class} && exists $by_tag->{$_}{$class}{$method}
exists $by_tag->{$_}{$class} exists $by_tag->{$_}{$class}{$method}
Truth table66%2/3
A && B
A= exists $by_tag->{$_}{$class}B= exists $by_tag->{$_}{$class}{$method}
ABresult
0X0
100
111
31 } __PACKAGE__->tags;
32 4 ▶ if ( $exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exists) 0 4 4
33 0 die "tags for $class->$method already exists, method redefinition perhaps?\n";
34 }
35  
36 4 foreach my $tag ( keys %tags ) {
37 5 $by_tag->{ $tag }{ $class }{ $method } = 1;
38 }
39 }
40  
41 5 ▶sub tags {
Subroutine tags: called CC=1 SCAR=0.0
Pod documented
42 5 return sort keys %{ $by_tag };
43 }
44  
45 5 ▶sub classes_with_tag {
Subroutine classes_with_tag: called CC=3 SCAR=11.0
Pod documented
46 5 my ( undef, $tag ) = @_;
47  
48 5 ▶ croak( "no tag specified" ) if not defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 1 4 5
49  
50 4 ▶ return if not exists $by_tag->{ $tag };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $by_tag->{$tag} 1 3 4
51  
52 3 return sort keys %{ $by_tag->{ $tag } };
53 }
54  
55 12 ▶sub methods_with_tag {
Subroutine methods_with_tag: called CC=4 SCAR=13.9
Pod documented
56 12 my ( undef, $class, $tag ) = @_;
57  
58 12 ▶ croak( "no class specified" ) if not defined $class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class 2 10 12
59 10 ▶ croak( "no tag specified" ) if not defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 2 8 10
60  
61 # avoid auto-vivication
62 8 ▶ return if not exists $by_tag->{ $tag };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $by_tag->{$tag} 2 6 8
63  
64 6 return sort keys %{ $by_tag->{ $tag }{ $class } };
65 }
66  
67 9 ▶sub method_has_tag {
Subroutine method_has_tag: called CC=7 SCAR=19.5
Pod documented
68 9 my ( undef, $class, $method, $tag ) = @_;
69  
70 9 ▶ croak( "no class specified" ) if not defined $class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $class 2 7 9
71 7 ▶ croak( "no method specified" ) if not defined $method;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $method 2 5 7
72 5 ▶ croak( "no tag specified" ) if not defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 2 3 5
73  
74 # avoid auto-vivication
75 3 ▶ return 0 if not exists $by_tag->{ $tag };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $by_tag->{$tag} 0 3 3
76 3 ▶ return 0 if not exists $by_tag->{ $tag }{ $class };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $by_tag->{$tag}{$class} 0 3 3
77  
78 3 ▶ return exists $by_tag->{ $tag }{ $class }{ $method }
Branch: 1 branch
BranchTrueFalseTotal
exists $by_tag->{$tag}{$class}{$method} ? : 1 2 3
79 ? 1
80 : 0;
81 }
82  
83 1 1;
84  
85 __END__
↑ Summary Tags.pm »