| 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
| |||||||||||||||||||||
| 16 | 0 | die "no tags defined\n"; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 4 | foreach my $tag ( @{ $tags } ) { | |||||||||||||||||||
| 20 | 5 | ▶ | if ( $tag !~ /^\w+$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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}
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}
| |||||||||||||||||||||
| 31 | } __PACKAGE__->tags; | ||||||||||||||||||||
| 32 | 4 | ▶ | if ( $exists ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 4 | ▶ | return if not exists $by_tag->{ $tag }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 59 | 10 | ▶ | croak( "no tag specified" ) if not defined $tag; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # avoid auto-vivication | ||||||||||||||||||||
| 62 | 8 | ▶ | return if not exists $by_tag->{ $tag }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 71 | 7 | ▶ | croak( "no method specified" ) if not defined $method; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 5 | ▶ | croak( "no tag specified" ) if not defined $tag; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | # avoid auto-vivication | ||||||||||||||||||||
| 75 | 3 | ▶ | return 0 if not exists $by_tag->{ $tag }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 3 | ▶ | return 0 if not exists $by_tag->{ $tag }{ $class }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 3 | ▶ | return exists $by_tag->{ $tag }{ $class }{ $method } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | ? 1 | ||||||||||||||||||||
| 80 | : 0; | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 1 | 1; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||