/usr/lib/perl5/Class/MOP/Method.pm is in libmoose-perl 2.0401-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | package Class::MOP::Method;
BEGIN {
$Class::MOP::Method::AUTHORITY = 'cpan:STEVAN';
}
{
$Class::MOP::Method::VERSION = '2.0401';
}
use strict;
use warnings;
use Carp 'confess';
use Scalar::Util 'weaken', 'reftype', 'blessed';
use base 'Class::MOP::Object';
# NOTE:
# if poked in the right way,
# they should act like CODE refs.
use overload '&{}' => sub { $_[0]->body }, fallback => 1;
# construction
sub wrap {
my ( $class, @args ) = @_;
unshift @args, 'body' if @args % 2 == 1;
my %params = @args;
my $code = $params{body};
if (blessed($code) && $code->isa(__PACKAGE__)) {
my $method = $code->clone;
delete $params{body};
Class::MOP::class_of($class)->rebless_instance($method, %params);
return $method;
}
elsif (!ref $code || 'CODE' ne reftype($code)) {
confess "You must supply a CODE reference to bless, not (" . ($code || 'undef') . ")";
}
($params{package_name} && $params{name})
|| confess "You must supply the package_name and name parameters";
my $self = $class->_new(\%params);
weaken($self->{associated_metaclass}) if $self->{associated_metaclass};
return $self;
}
sub _new {
my $class = shift;
return Class::MOP::Class->initialize($class)->new_object(@_)
if $class ne __PACKAGE__;
my $params = @_ == 1 ? $_[0] : {@_};
return bless {
'body' => $params->{body},
'associated_metaclass' => $params->{associated_metaclass},
'package_name' => $params->{package_name},
'name' => $params->{name},
'original_method' => $params->{original_method},
} => $class;
}
## accessors
sub associated_metaclass { shift->{'associated_metaclass'} }
sub attach_to_class {
my ( $self, $class ) = @_;
$self->{associated_metaclass} = $class;
weaken($self->{associated_metaclass});
}
sub detach_from_class {
my $self = shift;
delete $self->{associated_metaclass};
}
sub fully_qualified_name {
my $self = shift;
$self->package_name . '::' . $self->name;
}
sub original_method { (shift)->{'original_method'} }
sub _set_original_method { $_[0]->{'original_method'} = $_[1] }
# It's possible that this could cause a loop if there is a circular
# reference in here. That shouldn't ever happen in normal
# circumstances, since original method only gets set when clone is
# called. We _could_ check for such a loop, but it'd involve some sort
# of package-lexical variable, and wouldn't be terribly subclassable.
sub original_package_name {
my $self = shift;
$self->original_method
? $self->original_method->original_package_name
: $self->package_name;
}
sub original_name {
my $self = shift;
$self->original_method
? $self->original_method->original_name
: $self->name;
}
sub original_fully_qualified_name {
my $self = shift;
$self->original_method
? $self->original_method->original_fully_qualified_name
: $self->fully_qualified_name;
}
sub execute {
my $self = shift;
$self->body->(@_);
}
# We used to go through use Class::MOP::Class->clone_instance to do this, but
# this was awfully slow. This method may be called a number of times when
# classes are loaded (especially during Moose role application), so it is
# worth optimizing. - DR
sub clone {
my $self = shift;
my $clone = bless { %{$self}, @_ }, blessed($self);
$clone->_set_original_method($self);
return $clone;
}
1;
# ABSTRACT: Method Meta Object
=pod
=head1 NAME
Class::MOP::Method - Method Meta Object
=head1 VERSION
version 2.0401
=head1 DESCRIPTION
The Method Protocol is very small, since methods in Perl 5 are just
subroutines in a specific package. We provide a very basic
introspection interface.
=head1 METHODS
=over 4
=item B<< Class::MOP::Method->wrap($code, %options) >>
This is the constructor. It accepts a method body in the form of
either a code reference or a L<Class::MOP::Method> instance, followed
by a hash of options.
The options are:
=over 8
=item * name
The method name (without a package name). This is required if C<$code>
is a coderef.
=item * package_name
The package name for the method. This is required if C<$code> is a
coderef.
=item * associated_metaclass
An optional L<Class::MOP::Class> object. This is the metaclass for the
method's class.
=back
=item B<< $metamethod->clone(%params) >>
This makes a shallow clone of the method object. In particular,
subroutine reference itself is shared between all clones of a given
method.
When a method is cloned, the original method object will be available
by calling C<original_method> on the clone.
=item B<< $metamethod->body >>
This returns a reference to the method's subroutine.
=item B<< $metamethod->name >>
This returns the method's name
=item B<< $metamethod->package_name >>
This returns the method's package name.
=item B<< $metamethod->fully_qualified_name >>
This returns the method's fully qualified name (package name and
method name).
=item B<< $metamethod->associated_metaclass >>
This returns the L<Class::MOP::Class> object for the method, if one
exists.
=item B<< $metamethod->original_method >>
If this method object was created as a clone of some other method
object, this returns the object that was cloned.
=item B<< $metamethod->original_name >>
This returns the method's original name, wherever it was first
defined.
If this method is a clone of a clone (of a clone, etc.), this method
returns the name from the I<first> method in the chain of clones.
=item B<< $metamethod->original_package_name >>
This returns the method's original package name, wherever it was first
defined.
If this method is a clone of a clone (of a clone, etc.), this method
returns the package name from the I<first> method in the chain of
clones.
=item B<< $metamethod->original_fully_qualified_name >>
This returns the method's original fully qualified name, wherever it
was first defined.
If this method is a clone of a clone (of a clone, etc.), this method
returns the fully qualified name from the I<first> method in the chain
of clones.
=item B<< $metamethod->is_stub >>
Returns true if the method is just a stub:
sub foo;
=item B<< $metamethod->attach_to_class($metaclass) >>
Given a L<Class::MOP::Class> object, this method sets the associated
metaclass for the method. This will overwrite any existing associated
metaclass.
=item B<< $metamethod->detach_from_class >>
Removes any associated metaclass object for the method.
=item B<< $metamethod->execute(...) >>
This executes the method. Any arguments provided will be passed on to
the method itself.
=item B<< Class::MOP::Method->meta >>
This will return a L<Class::MOP::Class> instance for this class.
It should also be noted that L<Class::MOP> will actually bootstrap
this module by installing a number of attribute meta-objects into its
metaclass.
=back
=head1 AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Infinity Interactive, Inc..
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
|