| 1 | package MooseX::RoleFor::Meta::Role::Trait::RoleFor; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | BEGIN | ||||||||||||||||||||
| 8 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | $MooseX::RoleFor::Meta::Role::Trait::RoleFor::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||
| 10 | 1 | $MooseX::RoleFor::Meta::Role::Trait::RoleFor::VERSION = '0.003'; | |||||||||||||||||||
| 11 | } | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 1 | ▶ | use Carp qw[croak carp]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 1 | ▶ | use Scalar::Util qw[blessed]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | has role_is_for => ( | |||||||||||||||||||
| 20 | is => 'rw', | ||||||||||||||||||||
| 21 | isa => 'Undef|Str|ArrayRef[Str]', | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | has role_misapplication_consequence => ( | |||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||
| 26 | isa => enum([qw/croak carp/]), | ||||||||||||||||||||
| 27 | default => 'carp', | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | before apply => sub | ||||||||||||||||||||
| 31 | 11 | ▶ | { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=29.1
| |||||||||||||||||||||
| 32 | 11 | my ($meta, $thing, @options) = @_; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 11 | my $applying_to = $thing; | |||||||||||||||||||
| 35 | 11 | ▶ | if ($applying_to->isa('Moose::Meta::Class')) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | { | ||||||||||||||||||||
| 37 | 3 | $applying_to = $thing->name; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 11 | my @targets; | |||||||||||||||||||
| 41 | @targets = ref $meta->role_is_for | ||||||||||||||||||||
| 42 | 0 | ▶ | ? @{$meta->role_is_for} | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 43 | : ($meta->role_is_for) | ||||||||||||||||||||
| 44 | if defined $meta->role_is_for; | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 11 | ▶ | return unless @targets; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 11 | my $compliance = 0; | |||||||||||||||||||
| 49 | 11 | TARGET: foreach (@targets) | |||||||||||||||||||
| 50 | { | ||||||||||||||||||||
| 51 | 11 | ▶ | if ($applying_to->DOES($_)) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | { | ||||||||||||||||||||
| 53 | 6 | $compliance = 1; | |||||||||||||||||||
| 54 | 6 | last TARGET; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 11 | ▶ | return if $compliance; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | my $message = sprintf( | ||||||||||||||||||||
| 61 | "Role '%s' must only be applied to classes %s (not '%s')", | ||||||||||||||||||||
| 62 | $meta->name, | ||||||||||||||||||||
| 63 | 5 | ▶ | (join '|', map {"'$_'"} @targets), | ||||||||||||||||||
|
Condition33%1/3
ref $applying_to || $applying_to
MC/DC0%0/2
ref $applying_to || $applying_to
ref $applying_to
$applying_to
Truth table33%1/3
A || B
A= ref $applying_toB= $applying_to
| |||||||||||||||||||||
| 64 | (ref $applying_to || $applying_to), | ||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 5 | foreach (keys %INC) | |||||||||||||||||||
| 68 | { | ||||||||||||||||||||
| 69 | 1267 | s{\.pm$}{}; | |||||||||||||||||||
| 70 | 1267 | s{[/\\]}{::}g; | |||||||||||||||||||
| 71 | 1267 | ▶ | $Carp::Internal{$_}++ if /^(?:Class::MOP|Moose|MooseX)\b/ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 5 | ▶ | $meta->role_misapplication_consequence eq 'croak' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | ? croak($message) | ||||||||||||||||||||
| 76 | : carp($message); | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | foreach (keys %INC) | |||||||||||||||||||
| 79 | { | ||||||||||||||||||||
| 80 | 0 | s{\.pm$}{}; | |||||||||||||||||||
| 81 | 0 | s{[/\\]}{::}g; | |||||||||||||||||||
| 82 | 0 | ▶ | $Carp::Internal{$_}-- if /^(?:Class::MOP|Moose|MooseX)\b/ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | 1 | }; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 1 | 'Yay!'; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||