Myco Entity class attribute can be described using a metadata container. This container holds relevant information about the attribute in question.
To add an attribute to the class, the constructor of ::Attribute should only be used via ::Meta's add_attribute() method. The code block for adding an attribute to the class is demonstrated below:
```Perl
my $md = Myco::Entity::Meta( name => __PACKAGE__ );
$md->add_attribute(
name => 'doneness',
type => 'int',
readonly => 0, # default is read/write
access_list => {
rw => ['admin'],
ro => [qw(average_joes junior_admins)]
},
tangram_options => { required => 1},
synopsis => "How you'd like your meat cooked",
syntax_msg => "correct format, please!",
values => [qw(0 1 2 3 4 5)],
value_labels => {
0 => 'rare',
1 => 'medium-rare',
2 => 'medium',
3 => 'medium-well',
4 => 'well',
5 => 'charred'
},
ui => {
widget => [ 'popup_menu' ],
label => 'Cook until...',
},
);
```
After the attribute has been added, usage of the code continues with standard post-setup usage. Given a Myco::Entity::Meta enabled entity object $obj, introspect to obtain metadata. Get reference to the array of ::Meta::Attribute objects for $obj's class via the get_attributes() method. Finally, look up the type of an attribute and use the stored accessor coderef to set the attribute value.
```Perl
# ...given a Myco::Entity::Meta enabled entity object $obj
my $metadata = $obj->introspect;
my $attributes = $metadata->get_attributes;
# Look up attribute's type
my $type = $attributes->{doneness}->get_type;
# Use of stored accessor coderef - set doneness = 3
$attributes->{doneness}->setval($obj, 3);
```
Overall, the Myco::Entity::Meta::Attribute class is an essential tool for working with Myco Entity classes.
Version 1.22: N/A