| 1 | package MooseX::Role::Strict; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.05; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::Meta::Role::Strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Moose::Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | Moose::Exporter->setup_import_methods( also => 'Moose::Role' ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub init_meta { | ||||||||||||||||||||||||||
|
Subroutine
init_meta: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 1 | my ( $class, %opt ) = @_; | |||||||||||||||||||||||||||
| 15 | 1 | return Moose::Role->init_meta( ## | |||||||||||||||||||||||||||
| 16 | %opt, ## | ||||||||||||||||||||||||||||
| 17 | metaclass => 'MooseX::Meta::Role::Strict' | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | package # Hide from PAUSE | ||||||||||||||||||||||||||||
| 22 | MooseX::Meta::Role::Application::ToClass::Strict; | ||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | extends 'Moose::Meta::Role::Application::ToClass'; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | sub apply_methods { | ||||||||||||||||||||||||||
|
Subroutine
apply_methods: called CC=11 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 2 | my ( $self, $role, $class ) = @_; | |||||||||||||||||||||||||||
| 28 | 2 | my @implicitly_overridden; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | foreach my $method_name ( $role->get_method_list ) { | |||||||||||||||||||||||||||
| 31 | 4 | ▶ | next if 'meta' eq $method_name; # Moose auto-exports this | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | unless ( $self->is_method_excluded($method_name) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | # it if it has one already | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class->has_method($method_name) and $class->get_method($method_name)->body != $role->get_method($method_name)->body
MC/DC0%0/2
$class->has_method($method_name) and $class->get_method($method_name)->body != $role->get_method($method_name)->body
$class->has_method($method_name)
$class->get_method($method_name)->body != $role->get_method($method_name)->body
Truth table33%1/3
A and B
A= $class->has_method($method_name)B= $class->get_method($method_name)->body != $role->get_method($method_name)->body
| |||||||||||||||||||||||||||||
| 35 | $class->has_method($method_name) && | ||||||||||||||||||||||||||||
| 36 | # and if they are not the same thing ... | ||||||||||||||||||||||||||||
| 37 | $class->get_method($method_name)->body != $role->get_method($method_name)->body | ||||||||||||||||||||||||||||
| 38 | ) | ||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 1 | push @implicitly_overridden => $method_name; | |||||||||||||||||||||||||||
| 41 | 1 | next; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # add it, although it could be overridden | ||||||||||||||||||||||||||||
| 46 | 0 | $class->add_method( $method_name, | |||||||||||||||||||||||||||
| 47 | $role->get_method($method_name) ); | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | if ( $self->is_method_aliased($method_name) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | my $aliased_method_name = $self->get_method_aliases->{$method_name}; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # it if it has one already | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class->has_method($aliased_method_name) and $class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body
MC/DC0%0/2
$class->has_method($aliased_method_name) and $class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body
$class->has_method($aliased_method_name)
$class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body
Truth table0%0/3
A and B
A= $class->has_method($aliased_method_name)B= $class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body
| |||||||||||||||||||||||||||||
| 56 | $class->has_method($aliased_method_name) && | ||||||||||||||||||||||||||||
| 57 | # and if they are not the same thing ... | ||||||||||||||||||||||||||||
| 58 | $class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body | ||||||||||||||||||||||||||||
| 59 | ) | ||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | $class->throw_error("Cannot create a method alias if a local method of the same name exists"); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 0 | $class->add_method( $aliased_method_name, | |||||||||||||||||||||||||||
| 64 | $role->get_method($method_name) ); | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | ▶ | if (@implicitly_overridden) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | my $s = @implicitly_overridden > 1 ? "s" : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | my $class_name = $class->name; | |||||||||||||||||||||||||||
| 72 | 1 | my $role_name = $role->name; | |||||||||||||||||||||||||||
| 73 | 1 | my $methods = join ', ' => @implicitly_overridden; | |||||||||||||||||||||||||||
| 74 | # we use \n because we have no hope of guessing the right stack frame, | ||||||||||||||||||||||||||||
| 75 | # it's almost certainly never going to be the one above us | ||||||||||||||||||||||||||||
| 76 | 1 | $class->throw_error(<<" END_ERROR"); | |||||||||||||||||||||||||||
| 77 | The class $class_name has implicitly overridden the method$s ($methods) from | ||||||||||||||||||||||||||||
| 78 | role $role_name. If this is intentional, please exclude the method$s from | ||||||||||||||||||||||||||||
| 79 | composition to silence this warning (see Moose::Cookbook::Roles::Recipe2) | ||||||||||||||||||||||||||||
| 80 | END_ERROR | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # we must reset the cache here since | ||||||||||||||||||||||||||||
| 85 | # we are just aliasing methods, otherwise | ||||||||||||||||||||||||||||
| 86 | # the modifiers go wonky. | ||||||||||||||||||||||||||||
| 87 | 1 | $class->reset_package_cache_flag; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||