chromatic's recent blog got me curious about the Moose subroutine has
. I was looking at the Moose source code and noticed that inside the has
subroutine, there is a $meta
variable unpacked from @_
. Where does $meta
come from? I've started wading through the various Moose and Class::MOP modules. In many subroutines, it seems that $meta
is commonly found as the first argument in @_
, even though it is not specifically passed to it as an argument.
Edit: Here is the original source code for the has
subroutine:
sub has {
my $meta = shift;
my $name = shift;
Moose->throw_error('Usage: has \'name\' => ( key => value, ... )')
if @_ % 2 == 1;
my %options = ( definition_context => Moose::Util::_caller_info(), @_ );
my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
$meta->add_attribute( $_, %options ) for @$attrs;
}