Reputation: 1666
Does Moose have a way to get the class methods attributes. I learned from my previous questions here that some standalone modules like Sub::Talisman can get the module attributes.
If I run code below I get error "Invalid CODE attribute: Public at ..."
#============================
package BaseClass;
use Moose;
#============================
package SubClass;
use Moose;
extends qw(BaseClass);
sub greet : Public {
my $self = shift;
printf("Hello world.");
}
#============================
package main;
my $object = SubClass->new();
# I need to get the Public attribute of the sub greet in the SubClass package.
# if the sub has a Public attribute, call it, otherwise, die.
# does Moose have some methods to get the attributes, I know some other modules like
# Sub::Talisman can get the sub's attributes.
$object->greet();
#============================
I need to get the Public attribute of the sub greet in the SubClass package. If the sub has a Public attribute, I will do something, otherwise, something else.
Does Moose have some methods to get the attributes, I know some other modules like Sub::Talisman can get the sub's attributes.
Upvotes: 1
Views: 936
Reputation: 13664
There's MooseX::MethodAttributes which integrates attribute introspection stuff into the Moose metaobject protocol.
However, the particular error you are getting will not be solved by that. To eliminate that error you need to define an attribute called :Public
, so that Perl knows this attribute exists. Sub::Talisman and Attribute::Handlers are modules that could be used to define the attribute.
Upvotes: 2