Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 922449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:01:58+00:00 2026-05-15T19:01:58+00:00

chromatic’s recent blog got me curious about the Moose subroutine has . I was

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:01:59+00:00Added an answer on May 15, 2026 at 7:01 pm

    molecules comment in ysth answer:

    I’m not sure how the has subroutine gets converted to this closure, but this definitely shows the curried nature of the imported has

    Here is (hopefully!) a simple example of how this could be achieved (however I suspect Moose does it in a much more complex and better way!)

    Meta.pm

    package Meta;
    
    sub new {
        my $class = shift;
        bless { @_ }, $class;
    }
    
    sub has {
        my $meta = shift;
        print "Given => @_ \n";
        print "meta $_ => ", $meta->{$_}, "\n" for keys %$meta;
    }
    
    1;
    

    Import.pm

    package Import;
    use strict;
    use warnings;
    use Meta;
    
    # some arbitrary meta info!
    our $Meta = Meta->new( a => 'A', b => 'B' );
    
    sub import {
        my $caller = caller;
    
        # import 'has' into caller namespace
        no strict 'refs';
        *{$caller . '::has'} = sub { $Meta->has(@_) };
    }
    
    1;
    

    meta_has.pl

    use strict;
    use warnings;
    use Import;
    
    has name => ( is => 'rw', isa => 'Int' );
    

    Now if you run meta_has.pl you will get:

    # Given => name is rw isa Int 
    # meta a => A
    # meta b => B
    

    Hope that helps.

    /I3az/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a GLSL shader that simulates chromatic aberration for simple objects. I
I am looking for lightweight image processing tool that will resize images to JPEG
Who knows the most robust algorithm for a chromatic instrument tuner? I am trying
for a homework graph theory, I'm asked to determine the chromatic polynomial of the
There are many optimization problems that are known to be NP-hard, such as the
A while ago I came across this answer that introduced me to the obscure
This is a brute force attempt at the chromatic number of a matrix. It
I'm not sure scalar testing is the correct term for it but I mean
I'm trying to convert an function to create a HSV Circle from Delphi to
Following up on this question: Android: Manage contacts with lookup key (see below) I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.