« blib/lib/Moose/Util/TypeConstraints.pm
↑ Summary
blib/lib/Moose/Meta/Method/Accessor/Native/Hash/Writer.pm »
| 1 | package Class::MOP::Method::Wrapped; | ||||||||||||||||||||||||||||||||||||
| 2 | 459 | our $VERSION = '2.4001'; | |||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||
| 4 | 459 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 459 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 459 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 459 | ▶ | use Sub::Util 1.40 'set_subname'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | 459 | ▶ | use parent 'Class::MOP::Method'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | # NOTE: | ||||||||||||||||||||||||||||||||||||
| 13 | # this ugly beast is the result of trying | ||||||||||||||||||||||||||||||||||||
| 14 | # to micro optimize this as much as possible | ||||||||||||||||||||||||||||||||||||
| 15 | # while not completely loosing maintainability. | ||||||||||||||||||||||||||||||||||||
| 16 | # At this point it's "fast enough", after all | ||||||||||||||||||||||||||||||||||||
| 17 | # you can't get something for nothing :) | ||||||||||||||||||||||||||||||||||||
| 18 | 31737 | ▶ | my $_build_wrapped_method = sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||
| 19 | 31737 | my $modifier_table = shift; | |||||||||||||||||||||||||||||||||||
| 20 | my ($before, $after, $around) = ( | ||||||||||||||||||||||||||||||||||||
| 21 | $modifier_table->{before}, | ||||||||||||||||||||||||||||||||||||
| 22 | $modifier_table->{after}, | ||||||||||||||||||||||||||||||||||||
| 23 | $modifier_table->{around}, | ||||||||||||||||||||||||||||||||||||
| 24 | 31737 | ); | |||||||||||||||||||||||||||||||||||
| 25 | 31737 | ▶ | if (@$before && @$after) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
@$before and @$after
MC/DC100%2/2
@$before and @$after
@$before
@$after
Truth table100%3/3
A and B
A= @$beforeB= @$after
| |||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | $modifier_table->{cache} = sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||
| 27 | 4 | for my $c (@$before) { $c->(@_) }; | |||||||||||||||||||||||||||||||||||
| 28 | 4 | my @rval; | |||||||||||||||||||||||||||||||||||
| 29 | ((defined wantarray) ? | ||||||||||||||||||||||||||||||||||||
| 30 | ((wantarray) ? | ||||||||||||||||||||||||||||||||||||
| 31 | (@rval = $around->{cache}->(@_)) | ||||||||||||||||||||||||||||||||||||
| 32 | : | ||||||||||||||||||||||||||||||||||||
| 33 | ($rval[0] = $around->{cache}->(@_))) | ||||||||||||||||||||||||||||||||||||
| 34 | : | ||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | $around->{cache}->(@_)); | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 36 | 4 | for my $c (@$after) { $c->(@_) }; | |||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return wantarray ? @rval : $rval[0]; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||
| 40 | 17 | } | |||||||||||||||||||||||||||||||||||
| 41 | elsif (@$before) { | ||||||||||||||||||||||||||||||||||||
| 42 | 187 | ▶ | $modifier_table->{cache} = sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 43 | 187 | for my $c (@$before) { $c->(@_) }; | |||||||||||||||||||||||||||||||||||
| 44 | 187 | return $around->{cache}->(@_); | |||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||
| 46 | 167 | } | |||||||||||||||||||||||||||||||||||
| 47 | elsif (@$after) { | ||||||||||||||||||||||||||||||||||||
| 48 | 29 | ▶ | $modifier_table->{cache} = sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||
| 49 | 29 | my @rval; | |||||||||||||||||||||||||||||||||||
| 50 | ((defined wantarray) ? | ||||||||||||||||||||||||||||||||||||
| 51 | ((wantarray) ? | ||||||||||||||||||||||||||||||||||||
| 52 | (@rval = $around->{cache}->(@_)) | ||||||||||||||||||||||||||||||||||||
| 53 | : | ||||||||||||||||||||||||||||||||||||
| 54 | ($rval[0] = $around->{cache}->(@_))) | ||||||||||||||||||||||||||||||||||||
| 55 | : | ||||||||||||||||||||||||||||||||||||
| 56 | 29 | ▶ | $around->{cache}->(@_)); | ||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||
| 57 | 29 | for my $c (@$after) { $c->(@_) }; | |||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 59 | 3 | ▶ | return wantarray ? @rval : $rval[0]; | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||
| 61 | 46 | } | |||||||||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||||||||||
| 63 | 31507 | $modifier_table->{cache} = $around->{cache}; | |||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||
| 65 | 459 | }; | |||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||
| 67 | 15855 | ▶ | sub wrap { | ||||||||||||||||||||||||||||||||||
|
Subroutine
wrap: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 68 | 15855 | my ( $class, $code, %params ) = @_; | |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | 15855 | ▶ | (blessed($code) && $code->isa('Class::MOP::Method')) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($code) and $code->isa("Class::MOP::Method")
MC/DC50%1/2
builtin::blessed($code) and $code->isa("Class::MOP::Method")
builtin::blessed($code)
$code->isa("Class::MOP::Method")
Truth table66%2/3
A and B
A= builtin::blessed($code)B= $code->isa("Class::MOP::Method")
| |||||||||||||||||||||||||||||||||||||
| 71 | || $class->_throw_exception( CanOnlyWrapBlessedCode => params => \%params, | ||||||||||||||||||||||||||||||||||||
| 72 | class => $class, | ||||||||||||||||||||||||||||||||||||
| 73 | code => $code | ||||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | 15854 | my $modifier_table = { | |||||||||||||||||||||||||||||||||||
| 77 | cache => undef, | ||||||||||||||||||||||||||||||||||||
| 78 | orig => $code->body, | ||||||||||||||||||||||||||||||||||||
| 79 | before => [], | ||||||||||||||||||||||||||||||||||||
| 80 | after => [], | ||||||||||||||||||||||||||||||||||||
| 81 | around => { | ||||||||||||||||||||||||||||||||||||
| 82 | cache => $code->body, | ||||||||||||||||||||||||||||||||||||
| 83 | methods => [], | ||||||||||||||||||||||||||||||||||||
| 84 | }, | ||||||||||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||||||||||
| 86 | 15854 | $_build_wrapped_method->($modifier_table); | |||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | # get these from the original unless explicitly overridden | ||||||||||||||||||||||||||||||||||||
| 89 | 15854 | ▶ | my $pkg_name = $params{package_name} || $code->package_name; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$params{'package_name'} || $code->package_name
MC/DC0%0/2
$params{'package_name'} || $code->package_name
$params{'package_name'}
$code->package_name
Truth table66%2/3
A || B
A= $params{'package_name'}B= $code->package_name
| |||||||||||||||||||||||||||||||||||||
| 90 | 15854 | ▶ | my $method_name = $params{name} || $code->name; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$params{'name'} || $code->name
MC/DC0%0/2
$params{'name'} || $code->name
$params{'name'}
$code->name
Truth table66%2/3
A || B
A= $params{'name'}B= $code->name
| |||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | return $class->SUPER::wrap( | ||||||||||||||||||||||||||||||||||||
| 93 | 70033 | ▶ | sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
linearized_isa: called CC=1 SCAR=0.0
Subroutine
get_all_method_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 94 | my $wrapped | ||||||||||||||||||||||||||||||||||||
| 95 | = set_subname( "${pkg_name}::_wrapped_${method_name}" => | ||||||||||||||||||||||||||||||||||||
| 96 | 70033 | $modifier_table->{cache} ); | |||||||||||||||||||||||||||||||||||
| 97 | 70033 | return $wrapped->(@_) ; | |||||||||||||||||||||||||||||||||||
| 98 | }, | ||||||||||||||||||||||||||||||||||||
| 99 | 15854 | package_name => $pkg_name, | |||||||||||||||||||||||||||||||||||
| 100 | name => $method_name, | ||||||||||||||||||||||||||||||||||||
| 101 | original_method => $code, | ||||||||||||||||||||||||||||||||||||
| 102 | modifier_table => $modifier_table, | ||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | 15854 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 107 | 15854 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 108 | 15854 | ▶ | return Class::MOP::Class->initialize($class)->new_object(@_) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 109 | if $class ne __PACKAGE__; | ||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||
| 111 | 15853 | ▶ | my $params = @_ == 1 ? $_[0] : {@_}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | return bless { | ||||||||||||||||||||||||||||||||||||
| 114 | # inherited from Class::MOP::Method | ||||||||||||||||||||||||||||||||||||
| 115 | 'body' => $params->{body}, | ||||||||||||||||||||||||||||||||||||
| 116 | 'associated_metaclass' => $params->{associated_metaclass}, | ||||||||||||||||||||||||||||||||||||
| 117 | 'package_name' => $params->{package_name}, | ||||||||||||||||||||||||||||||||||||
| 118 | 'name' => $params->{name}, | ||||||||||||||||||||||||||||||||||||
| 119 | 'original_method' => $params->{original_method}, | ||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||
| 121 | # defined in this class | ||||||||||||||||||||||||||||||||||||
| 122 | 'modifier_table' => $params->{modifier_table} | ||||||||||||||||||||||||||||||||||||
| 123 | 15853 | } => $class; | |||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | sub get_original_method { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_original_method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 127 | 2 | my $code = shift; | |||||||||||||||||||||||||||||||||||
| 128 | 2 | $code->original_method; | |||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||
| 131 | 163 | ▶ | sub add_before_modifier { | ||||||||||||||||||||||||||||||||||
|
Subroutine
add_before_modifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 132 | 163 | my $code = shift; | |||||||||||||||||||||||||||||||||||
| 133 | 163 | my $modifier = shift; | |||||||||||||||||||||||||||||||||||
| 134 | 163 | unshift @{$code->{'modifier_table'}->{before}} => $modifier; | |||||||||||||||||||||||||||||||||||
| 135 | 163 | $_build_wrapped_method->($code->{'modifier_table'}); | |||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | sub before_modifiers { | ||||||||||||||||||||||||||||||||||
|
Subroutine
before_modifiers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 139 | 4 | my $code = shift; | |||||||||||||||||||||||||||||||||||
| 140 | 4 | return @{$code->{'modifier_table'}->{before}}; | |||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||
| 143 | 60 | ▶ | sub add_after_modifier { | ||||||||||||||||||||||||||||||||||
|
Subroutine
add_after_modifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 144 | 60 | my $code = shift; | |||||||||||||||||||||||||||||||||||
| 145 | 60 | my $modifier = shift; | |||||||||||||||||||||||||||||||||||
| 146 | 60 | push @{$code->{'modifier_table'}->{after}} => $modifier; | |||||||||||||||||||||||||||||||||||
| 147 | 60 | $_build_wrapped_method->($code->{'modifier_table'}); | |||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | 4 | ▶ | sub after_modifiers { | ||||||||||||||||||||||||||||||||||
|
Subroutine
after_modifiers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 151 | 4 | my $code = shift; | |||||||||||||||||||||||||||||||||||
| 152 | 4 | return @{$code->{'modifier_table'}->{after}}; | |||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||
| 156 | # NOTE: | ||||||||||||||||||||||||||||||||||||
| 157 | # this is another possible candidate for | ||||||||||||||||||||||||||||||||||||
| 158 | # optimization as well. There is an overhead | ||||||||||||||||||||||||||||||||||||
| 159 | # associated with the currying that, if | ||||||||||||||||||||||||||||||||||||
| 160 | # eliminated might make around modifiers | ||||||||||||||||||||||||||||||||||||
| 161 | # more manageable. | ||||||||||||||||||||||||||||||||||||
| 162 | 15660 | ▶ | my $compile_around_method = sub {{ | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 163 | 15660 | my $f1 = pop; | |||||||||||||||||||||||||||||||||||
| 164 | 31333 | ▶ | return $f1 unless @_; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 165 | 15673 | my $f2 = pop; | |||||||||||||||||||||||||||||||||||
| 166 | 15673 | ▶ | push @_, sub { $f2->( $f1, @_ ) }; | ||||||||||||||||||||||||||||||||||
|
Subroutine
_wrapped_linearized_isa: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 167 | 15673 | redo; | |||||||||||||||||||||||||||||||||||
| 168 | 459 | }}; | |||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||
| 170 | 15660 | ▶ | sub add_around_modifier { | ||||||||||||||||||||||||||||||||||
|
Subroutine
add_around_modifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 171 | 15660 | my $code = shift; | |||||||||||||||||||||||||||||||||||
| 172 | 15660 | my $modifier = shift; | |||||||||||||||||||||||||||||||||||
| 173 | 15660 | unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier; | |||||||||||||||||||||||||||||||||||
| 174 | $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->( | ||||||||||||||||||||||||||||||||||||
| 175 | 15660 | @{$code->{'modifier_table'}->{around}->{methods}}, | |||||||||||||||||||||||||||||||||||
| 176 | $code->{'modifier_table'}->{orig} | ||||||||||||||||||||||||||||||||||||
| 177 | 15660 | ); | |||||||||||||||||||||||||||||||||||
| 178 | 15660 | $_build_wrapped_method->($code->{'modifier_table'}); | |||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||
| 182 | 459 | ▶ | sub around_modifiers { | ||||||||||||||||||||||||||||||||||
|
Subroutine
around_modifiers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 183 | 4 | my $code = shift; | |||||||||||||||||||||||||||||||||||
| 184 | 4 | return @{$code->{'modifier_table'}->{around}->{methods}}; | |||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | sub _make_compatible_with { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_make_compatible_with: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||
| 188 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 189 | 5 | my ($other) = @_; | |||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | # XXX: this is pretty gross. the issue here is that CMOP::Method::Wrapped | ||||||||||||||||||||||||||||||||||||
| 192 | # objects are subclasses of CMOP::Method, but when we get to moose, they'll | ||||||||||||||||||||||||||||||||||||
| 193 | # need to be compatible with Moose::Meta::Method, which isn't possible. the | ||||||||||||||||||||||||||||||||||||
| 194 | # right solution here is to make ::Wrapped into a role that gets applied to | ||||||||||||||||||||||||||||||||||||
| 195 | # whatever the method_metaclass happens to be and get rid of | ||||||||||||||||||||||||||||||||||||
| 196 | # wrapped_method_metaclass entirely, but that's not going to happen until | ||||||||||||||||||||||||||||||||||||
| 197 | # we ditch cmop and get roles into the bootstrapping, so. i'm not | ||||||||||||||||||||||||||||||||||||
| 198 | # maintaining the previous behavior of turning them into instances of the | ||||||||||||||||||||||||||||||||||||
| 199 | # new method_metaclass because that's equally broken, and at least this way | ||||||||||||||||||||||||||||||||||||
| 200 | # any issues will at least be detectable and potentially fixable. -doy | ||||||||||||||||||||||||||||||||||||
| 201 | 5 | ▶ | return $self unless $other->_is_compatible_with($self->_real_ref_name); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||
| 203 | 0 | return $self->SUPER::_make_compatible_with(@_); | |||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||
| 206 | 459 | 1; | |||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||
| 208 | # ABSTRACT: Method Meta Object for methods with before/after/around modifiers | ||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||
| 210 | __END__ | ||||||||||||||||||||||||||||||||||||