| 1 | package MooseX::MethodAttributes::Role::Meta::Class; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: metaclass role for storing code attributes | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 19 | our $VERSION = '0.32'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use Moose::Util qw/find_meta does_role/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 19 | with qw/ | |||||||||||||||||||||||||||
| 12 | MooseX::MethodAttributes::Role::Meta::Map | ||||||||||||||||||||||||||||
| 13 | /; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #pod =method get_method_with_attributes_list | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod Gets the list of meta methods for local methods of this class that have | ||||||||||||||||||||||||||||
| 18 | #pod attributes in the order they have been registered. | ||||||||||||||||||||||||||||
| 19 | #pod | ||||||||||||||||||||||||||||
| 20 | #pod =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 24 | ▶ | sub get_method_with_attributes_list { | ||||||||||||||||||||||||||
|
Subroutine
get_method_with_attributes_list: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||
| 24 | 24 | my @methods = map { $self->get_method($_) } $self->get_method_list; | |||||||||||||||||||||||||||
| 25 | 24 | my %order; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | 24 | my $i = 0; | |||||||||||||||||||||||||||
| 29 | 24 | $order{$_} = $i++ for @{ $self->_method_attribute_list }; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | return map { | ||||||||||||||||||||||||||||
| 33 | 47 | $_->[1] | |||||||||||||||||||||||||||
| 34 | } sort { | ||||||||||||||||||||||||||||
| 35 | 42 | $order{ $a->[0] } <=> $order{ $b->[0] } | |||||||||||||||||||||||||||
| 36 | } map { | ||||||||||||||||||||||||||||
| 37 | 57 | my $addr = 0 + $_->_get_attributed_coderef; | |||||||||||||||||||||||||||
| 38 | 57 | ▶ | exists $self->_method_attribute_map->{$addr} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | ? [$addr, $_] | ||||||||||||||||||||||||||||
| 40 | : () | ||||||||||||||||||||||||||||
| 41 | } grep { | ||||||||||||||||||||||||||||
| 42 | 24 | $_->can('_get_attributed_coderef') | |||||||||||||||||||||||||||
| 43 | } @methods; | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | #pod =method get_all_methods_with_attributes | ||||||||||||||||||||||||||||
| 47 | #pod | ||||||||||||||||||||||||||||
| 48 | #pod Gets the list of meta methods of local and inherited methods of this class, | ||||||||||||||||||||||||||||
| 49 | #pod that have attributes. Base class methods come before subclass methods. Methods | ||||||||||||||||||||||||||||
| 50 | #pod of one class have the order they have been declared in. | ||||||||||||||||||||||||||||
| 51 | #pod | ||||||||||||||||||||||||||||
| 52 | #pod =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 11 | ▶ | sub get_all_methods_with_attributes { | ||||||||||||||||||||||||||
|
Subroutine
get_all_methods_with_attributes: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||
| 56 | 11 | my %seen; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | return reverse grep { | ||||||||||||||||||||||||||||
| 59 | 39 | !$seen{ $_->name }++ | |||||||||||||||||||||||||||
| 60 | } reverse map { | ||||||||||||||||||||||||||||
| 61 | 11 | my $meth; | |||||||||||||||||||||||||||
| 62 | 42 | my $meta = find_meta($_); | |||||||||||||||||||||||||||
| 63 | 42 | ▶ | ($meta && ($meth = $meta->can('get_method_with_attributes_list'))) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$meta and $meth = $meta->can("get_method_with_attributes_list")
MC/DC50%1/2
$meta and $meth = $meta->can("get_method_with_attributes_list")
$meta
$meth = $meta->can("get_method_with_attributes_list")
Truth table66%2/3
A and B
A= $metaB= $meth = $meta->can("get_method_with_attributes_list")
| |||||||||||||||||||||||||||||
| 64 | ? $meta->$meth | ||||||||||||||||||||||||||||
| 65 | : () | ||||||||||||||||||||||||||||
| 66 | } reverse $self->linearized_isa; | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | #pod =method get_nearest_methods_with_attributes | ||||||||||||||||||||||||||||
| 70 | #pod | ||||||||||||||||||||||||||||
| 71 | #pod The same as get_all_methods_with_attributes, except that methods from parent classes | ||||||||||||||||||||||||||||
| 72 | #pod are not included if there is an attribute-less method in a child class. | ||||||||||||||||||||||||||||
| 73 | #pod | ||||||||||||||||||||||||||||
| 74 | #pod For example, given: | ||||||||||||||||||||||||||||
| 75 | #pod | ||||||||||||||||||||||||||||
| 76 | #pod package BaseClass; | ||||||||||||||||||||||||||||
| 77 | #pod | ||||||||||||||||||||||||||||
| 78 | #pod sub foo : Attr {} | ||||||||||||||||||||||||||||
| 79 | #pod | ||||||||||||||||||||||||||||
| 80 | #pod sub bar : Attr {} | ||||||||||||||||||||||||||||
| 81 | #pod | ||||||||||||||||||||||||||||
| 82 | #pod package SubClass; | ||||||||||||||||||||||||||||
| 83 | #pod use base qw/BaseClass/; | ||||||||||||||||||||||||||||
| 84 | #pod | ||||||||||||||||||||||||||||
| 85 | #pod sub foo {} | ||||||||||||||||||||||||||||
| 86 | #pod | ||||||||||||||||||||||||||||
| 87 | #pod after bar => sub {} | ||||||||||||||||||||||||||||
| 88 | #pod | ||||||||||||||||||||||||||||
| 89 | #pod C<< SubClass->meta->get_all_methods_with_attributes >> will return | ||||||||||||||||||||||||||||
| 90 | #pod C<< BaseClass->meta->get_method('foo') >> for the above example, but | ||||||||||||||||||||||||||||
| 91 | #pod this method will not, and will return the wrapped bar method, whereas | ||||||||||||||||||||||||||||
| 92 | #pod C<< get_all_methods_with_attributes >> will return the original method. | ||||||||||||||||||||||||||||
| 93 | #pod | ||||||||||||||||||||||||||||
| 94 | #pod =cut | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | ▶ | sub get_nearest_methods_with_attributes { | ||||||||||||||||||||||||||
|
Subroutine
get_nearest_methods_with_attributes: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 98 | my @list = map { | ||||||||||||||||||||||||||||
| 99 | 3 | my $m = $self->find_method_by_name($_->name); | |||||||||||||||||||||||||||
| 100 | 8 | my $meth = $m->can('attributes'); | |||||||||||||||||||||||||||
| 101 | 8 | ▶ | my $attrs = $meth ? $m->$meth() : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 8 | ▶ | scalar @{ $attrs } ? ( $m ) : ( ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | } $self->get_all_methods_with_attributes; | ||||||||||||||||||||||||||||
| 104 | 3 | return @list; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 19 | foreach my $type (qw/after before around/) { | |||||||||||||||||||||||||||
| 108 | 22 | ▶ | around "add_${type}_method_modifier" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 109 | 22 | my $orig = shift; | |||||||||||||||||||||||||||
| 110 | 22 | my $meta = shift; | |||||||||||||||||||||||||||
| 111 | 22 | my ($method_name) = @_; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 22 | my $code = $meta->$orig(@_); | |||||||||||||||||||||||||||
| 114 | 22 | my $method = $meta->get_method($method_name); | |||||||||||||||||||||||||||
| 115 | 22 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method") or does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method::Wrapped")
MC/DC50%1/2
does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method") or does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method::Wrapped")
does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method")
does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method::Wrapped")
Truth table66%2/3
A or B
A= does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method")B= does_role($method->get_original_method, "MooseX::MethodAttributes::Role::Meta::Method::Wrapped")
| |||||||||||||||||||||||||||||
| 116 | does_role($method->get_original_method, 'MooseX::MethodAttributes::Role::Meta::Method') | ||||||||||||||||||||||||||||
| 117 | || does_role($method->get_original_method, 'MooseX::MethodAttributes::Role::Meta::Method::Wrapped') | ||||||||||||||||||||||||||||
| 118 | ) { | ||||||||||||||||||||||||||||
| 119 | 16 | MooseX::MethodAttributes::Role::Meta::Method::Wrapped->meta->apply($method); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 22 | return $code; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 57 | } | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 19 | 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||