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 5987057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:45:37+00:00 2026-05-22T22:45:37+00:00

Using __PACKAGE__->meta->get_attribute(‘foo’) , you can access the foo attribute definitions in a given class,

  • 0

Using __PACKAGE__->meta->get_attribute('foo'), you can access the foo attribute definitions in a given class, which can be useful.

#!perl
package Bla;
use Moose;
has bla => is => 'ro', isa => 'Str';
has hui => is => 'ro', isa => 'Str', required => 1;
no Moose; __PACKAGE__->meta->make_immutable;

package Blub;
use Moose;
has bla => is => 'ro', isa => 'Str';
has hui => is => 'ro', isa => 'Str', required => 0;
no Moose; __PACKAGE__->meta->make_immutable;

package Blubbel;
use Moose;
extends 'Blub';
no Moose; __PACKAGE__->meta->make_immutable;

package main;
use Test::More;
use Test::Exception;

my $attr = Bla->meta->get_attribute('hui');
is $attr->is_required, 1;

$attr = Blub->meta->get_attribute('hui');
is $attr->is_required, 0;

$attr = Blubbel->meta->get_attribute('hui');
is $attr, undef;
throws_ok { $attr->is_required }
  qr/Can't call method "is_required" on an undefined value/;
diag 'Attribute aus Basisklassen werden hier nicht gefunden.';

done_testing;

As evidenced by this little code sample, however, this cannot be used to access attribute definitions in base classes, which would be even more useful for my particular case. Is there a way to achieve what I want?

  • 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-22T22:45:37+00:00Added an answer on May 22, 2026 at 10:45 pm

    NOTE that get_attribute does not search superclasses, for that you need to use find_attribute_by_name

    — Class::MOP::Class docs. And indeed this code passes:

    my $attr = Bla->meta->find_attribute_by_name('hui');
    is $attr->is_required, 1;
    
    $attr = Blub->meta->find_attribute_by_name('hui');
    is $attr->is_required, 0;
    
    $attr = Blubbel->meta->find_attribute_by_name('hui');
    is $attr->is_required, 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an installation package using Wix which installs a Windows service on
I'm monkey patching a package using a technique given at the beginning of How
I distribute my application using a VS2008 install package, which normally works great. When
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I'm calling a SSIS package using LoadPackage(...). Is it possible to make this call
I am building a Setup Package using VS2008. This is a regular setup package
In Java, we're using the following package to programmatically create excel documents: org.apache.poi.hssf If
I package our server releases into zip files using a batch file (Windows), running
when calling a SSIS package (C# app) using LoadFromSqlServer, does the user account have
I'm using LaTeX 's listings package to format source code. Unfortunately I get curly

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.