| 1 | 5 | ▶ | use 5.008; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | package Role::Commons::Authority; | ||||||||||||
| 6 | |||||||||||||
| 7 | 5 | ▶ | use Carp qw[croak]; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 5 | ▶ | use match::simple qw[match]; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 5 | ▶ | use Scalar::Util qw[blessed]; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 5 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 5 | ▶ | use Moo::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 5 | $Role::Commons::Authority::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||
| 14 | 5 | $Role::Commons::Authority::VERSION = '0.104'; | |||||||||||
| 15 | } | ||||||||||||
| 16 | |||||||||||||
| 17 | 5 | our %ENABLE_SHARED; | |||||||||||
| 18 | 5 | our %SHARED_AUTHORITIES; | |||||||||||
| 19 | |||||||||||||
| 20 | 4 | ▶ | our $setup_for_class = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.5
| |||||||||||||
| 21 | 4 | my ($role, $package, %args) = @_; | |||||||||||
| 22 | |||||||||||||
| 23 | 4 | ▶ | if ( exists $args{-authorities} ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | { | ||||||||||||
| 25 | 0 | $ENABLE_SHARED{ $package } = 1; | |||||||||||
| 26 | |||||||||||||
| 27 | ref($args{-authorities}) eq 'ARRAY' and | ||||||||||||
| 28 | 0 | ▶ | $SHARED_AUTHORITIES{ $package } = $args{-authorities}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | } | ||||||||||||
| 30 | 5 | }; | |||||||||||
| 31 | |||||||||||||
| 32 | sub AUTHORITY | ||||||||||||
| 33 | 11 | ▶ | { | ||||||||||
|
Subroutine
AUTHORITY: called CC=10 SCAR=24.6
Pod
documented
| |||||||||||||
| 34 | 11 | my ($invocant, $test) = @_; | |||||||||||
| 35 | 11 | ▶ | $invocant = ref $invocant if blessed($invocant); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | |||||||||||||
| 37 | 11 | my @authorities = do { | |||||||||||
| 38 | 5 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | 11 | my @a = ${"$invocant\::AUTHORITY"}; | |||||||||||
| 40 | 11 | ▶ | if (exists $ENABLE_SHARED{ $invocant }) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | { | ||||||||||||
| 42 | 0 | ▶ | push @a, @{$SHARED_AUTHORITIES{$invocant} || []}; | ||||||||||
|
Condition0%0/2
$Role::Commons::Authority::SHARED_AUTHORITIES{$invocant} || []
MC/DC0%0/1
$Role::Commons::Authority::SHARED_AUTHORITIES{$invocant} || []
$Role::Commons::Authority::SHARED_AUTHORITIES{$invocant}
Truth table0%0/2
A
A= $Role::Commons::Authority::SHARED_AUTHORITIES{$invocant}
| |||||||||||||
| 43 | 0 | push @a, @{"$invocant\::AUTHORITIES"}; | |||||||||||
| 44 | } | ||||||||||||
| 45 | 11 | @a; | |||||||||||
| 46 | }; | ||||||||||||
| 47 | |||||||||||||
| 48 | 11 | ▶ | if (scalar @_ > 1) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | { | ||||||||||||
| 50 | 9 | my $ok = undef; | |||||||||||
| 51 | 9 | AUTH: for my $A (@authorities) | |||||||||||
| 52 | { | ||||||||||||
| 53 | 9 | ▶ | if (match($A, $test)) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | { | ||||||||||||
| 55 | 4 | $ok = $A; | |||||||||||
| 56 | 4 | last AUTH; | |||||||||||
| 57 | } | ||||||||||||
| 58 | } | ||||||||||||
| 59 | 9 | ▶ | return $ok if defined $ok; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | |||||||||||||
| 61 | @authorities | ||||||||||||
| 62 | 5 | ▶ | ? croak("Invocant ($invocant) has authority '$authorities[0]'") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | : croak("Invocant ($invocant) has no authority defined"); | ||||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 2 | ▶ | wantarray ? @authorities : $authorities[0]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 5 | 1; | |||||||||||
| 70 | |||||||||||||
| 71 | __END__ | ||||||||||||