| 1 | package Mouse::Meta::Role; | ||||||||||||||||||||
| 2 | 285 | ▶ | use Mouse::Util qw(:meta); # enables strict and warnings | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 285 | ▶ | use Mouse::Meta::Module; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 285 | our @ISA = qw(Mouse::Meta::Module); | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | sub method_metaclass; | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 262 | ▶ | sub _construct_meta { | ||||||||||||||||||
|
Subroutine
_construct_meta: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 10 | 262 | my $class = shift; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 262 | my %args = @_; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 262 | $args{methods} = {}; | |||||||||||||||||||
| 15 | 262 | $args{attributes} = {}; | |||||||||||||||||||
| 16 | 262 | $args{required_methods} = []; | |||||||||||||||||||
| 17 | 262 | $args{roles} = []; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 262 | ▶ | my $self = bless \%args, ref($class) || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 20 | 262 | ▶ | if($class ne __PACKAGE__){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 58 | $self->meta->_initialize_object($self, \%args); | |||||||||||||||||||
| 22 | } | ||||||||||||||||||||
| 23 | 262 | return $self; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 66 | ▶ | sub create_anon_role{ | ||||||||||||||||||
|
Subroutine
create_anon_role: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 27 | 66 | my $self = shift; | |||||||||||||||||||
| 28 | 66 | return $self->create(undef, @_); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | sub is_anon_role; | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | sub get_roles; | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 12 | ▶ | sub calculate_all_roles { | ||||||||||||||||||
|
Subroutine
calculate_all_roles: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 36 | 12 | my $self = shift; | |||||||||||||||||||
| 37 | 12 | my %seen; | |||||||||||||||||||
| 38 | 14 | return grep { !$seen{ $_->name }++ } | |||||||||||||||||||
| 39 | 12 | ($self, map { $_->calculate_all_roles } @{ $self->get_roles }); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 162 | ▶ | sub get_required_method_list{ | ||||||||||||||||||
|
Subroutine
get_required_method_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 43 | 162 | return @{ $_[0]->{required_methods} }; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 180 | ▶ | sub add_required_methods { | ||||||||||||||||||
|
Subroutine
add_required_methods: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 47 | 180 | my($self, @methods) = @_; | |||||||||||||||||||
| 48 | 180 | my %required = map{ $_ => 1 } @{$self->{required_methods}}; | |||||||||||||||||||
| 49 | 180 | ▶ | push @{$self->{required_methods}}, grep{ !$required{$_}++ && !$self->has_method($_) } @methods; | ||||||||||||||||||
|
Condition100%3/3
$required{$_}++ || $self->has_method($_)
MC/DC100%2/2
$required{$_}++ || $self->has_method($_)
$required{$_}++
$self->has_method($_)
Truth table100%3/3
A || B
A= $required{$_}++B= $self->has_method($_)
| |||||||||||||||||||||
| 50 | 180 | return; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 10 | ▶ | sub requires_method { | ||||||||||||||||||
|
Subroutine
requires_method: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 54 | 10 | my($self, $name) = @_; | |||||||||||||||||||
| 55 | 10 | return scalar( grep{ $_ eq $name } @{ $self->{required_methods} } ) != 0; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 88 | ▶ | sub add_attribute { | ||||||||||||||||||
|
Subroutine
add_attribute: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 59 | 88 | my $self = shift; | |||||||||||||||||||
| 60 | 88 | my $name = shift; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 88 | ▶ | $self->{attributes}->{$name} = (@_ == 1) ? $_[0] : { @_ }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 88 | return; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 302 | ▶ | sub apply { | ||||||||||||||||||
|
Subroutine
apply: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 67 | 302 | my $self = shift; | |||||||||||||||||||
| 68 | 302 | my $consumer = shift; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 302 | require 'Mouse/Meta/Role/Application.pm'; | |||||||||||||||||||
| 71 | 302 | return Mouse::Meta::Role::Application->new(@_)->apply($self, $consumer); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 52 | ▶ | sub combine { | ||||||||||||||||||
|
Subroutine
combine: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 75 | 52 | my($self, @role_specs) = @_; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 52 | require 'Mouse/Meta/Role/Composite.pm'; | |||||||||||||||||||
| 78 | 52 | return Mouse::Meta::Role::Composite->new(roles => \@role_specs); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | sub add_before_method_modifier; | ||||||||||||||||||||
| 82 | sub add_around_method_modifier; | ||||||||||||||||||||
| 83 | sub add_after_method_modifier; | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub get_before_method_modifiers; | ||||||||||||||||||||
| 86 | sub get_around_method_modifiers; | ||||||||||||||||||||
| 87 | sub get_after_method_modifiers; | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 16 | ▶ | sub add_override_method_modifier{ | ||||||||||||||||||
|
Subroutine
add_override_method_modifier: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 90 | 16 | my($self, $method_name, $method) = @_; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 16 | ▶ | if($self->has_method($method_name)){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | # This error happens in the override keyword or during role composition, | ||||||||||||||||||||
| 94 | # so I added a message, "A local method of ...", only for compatibility (gfx) | ||||||||||||||||||||
| 95 | 2 | $self->throw_error("Cannot add an override of method '$method_name' " | |||||||||||||||||||
| 96 | . "because there is a local version of '$method_name'" | ||||||||||||||||||||
| 97 | . "(A local method of the same name as been found)"); | ||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 14 | $self->{override_method_modifiers}->{$method_name} = $method; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 2 | ▶ | sub get_override_method_modifier { | ||||||||||||||||||
|
Subroutine
get_override_method_modifier: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 104 | 2 | my ($self, $method_name) = @_; | |||||||||||||||||||
| 105 | 2 | return $self->{override_method_modifiers}->{$method_name}; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 1002 | ▶ | sub does_role { | ||||||||||||||||||
|
Subroutine
does_role: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 109 | 1002 | my ($self, $role_name) = @_; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 1002 | ▶ | (defined $role_name) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | || $self->throw_error("You must supply a role name to look for"); | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 1002 | ▶ | $role_name = $role_name->name if ref $role_name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | # if we are it,.. then return true | ||||||||||||||||||||
| 117 | 1002 | ▶ | return 1 if $role_name eq $self->name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | # otherwise.. check our children | ||||||||||||||||||||
| 119 | 715 | for my $role (@{ $self->get_roles }) { | |||||||||||||||||||
| 120 | 498 | ▶ | return 1 if $role->does_role($role_name); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | 448 | return 0; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 285 | 1; | |||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||