Ben Sommer > Myco-1.22 > Myco::Entity::Meta::Attribute

Download:
Myco-1.22.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Source  

NAME ^

Myco::Entity::Meta::Attribute

SYNOPSIS ^

 # Note this class is normally used only via
 #   Myco::Entity::Meta

 ## Within an entity class definition - add attribute to class
 #   ::Attribute's constructor should only be used via
 #     ::Meta's add_attribute() as shown:

 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...',
          },
  );

 ## Typical post-setup usage
 #   ...given a Myco::Entity::Meta enabled entity object $obj

 my $metadata = $obj->introspect;
 # Get reference to array of ::Meta::Attribute objects for $obj's class
 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);

DESCRIPTION ^

Container for meta data describing an attribute of a Myco Entity class

COMMON ENTITY INTERFACE ^

Constructor, accessors, and other methods -- as inherited from Myco::Entity

ATTRIBUTES ^

Attributes may be initially set during object construction (with new()) but otherwise are accessed solely through accessor methods. Typical usage:

A listing of available attributes follows:

access_list

 type: hash ref

Hash containing either or both of these keys: rw, ro (for read-write, read-only, respectively). Each key corresponds to a anonymous array of names of user roles authorized for the given type of access.

getter

 type: code ref

Reference to getter method of entity attribute.

name

 type: string   required: not empty

Name of entity attribute.

readonly

 type: int (boolean)

If set to true calls to entity attribute setter will result in throwing of exception type Myco::Exception::MNI.

setter

 type: code ref

Reference to setter method of entity attribute.

synopsis

 type: string

Short (a few words) description of entity attribute.

tangram_options

 type: hash ref

Hash of Class::Tangram entity attribute options.

template

 type: int (boolean)

If set to true entity attribute is marked as a "template", meaning the following:

type

 type: string

Data type of entity attribute; must be a valid Class::Tangram data type. [required: not undef]

type_options

 type: hash ref

Additional detail regarding the entity attribute data type. Valid option(s):

syntax_msg

 type: string

Short (under one line) description of valid entity attribute value syntax.

values

 type: array ref

Array of all valid values for this entity attribute. Use only when appropriate. By default, setting this metadata parameter results in a "popup_menu" being used as the user interface widget type, with values displayed in the order given.

value_labels

 type: hash ref

Hash mapping entity attribute values (which should be the same as those specified with the "values" parameter) to a user visible label; for use when generating value selection user interface widget for this entity attribute.

ui

 type: hash ref

 {
  label  => 'Sprocket',
  widget => ['popup_menu', -rows => 2, -columns => 2],
  # etc.
 }

A data structure containing instructions for generating a user interface element for this entity attribute. This data structure used in the creation of a Myco::Entity::Meta::Attribute::UI object which becomes part of the attribute metadata. Run-time access to this metadata should only occur via accessor methods.

The following hash keys (corresponding to ::Meta::Attribute::UI object attributes) are allowed:

ADDED CLASS / INSTANCE METHODS ^

get_type_defaults

Returns a reference to a hash (key == attribute type) of default meta data info which is used during attribute object initialization.

getval

 # Given $attrmeta, an ::Attribute metadata object for some class,
 #   and $entity, an instance of same class
 $attrval = $attrmeta->getval($entity);

 # Complete, but unrealistic example of use
 $attrval = $entity->introspect->get_attributes->{attr1}
                                            ->getval($entity);

Get the value of an attribute of $entity, utilizing the getter code reference retrieved via get_getter.

setval

 # Given $attrmeta, an ::Attribute metadata object for some class,
 #   and $entity, an instance of same class
 $attrval = $attrmeta->setval($entity, $value);

 # Complete, but unrealistic example of use
 $attrval = $entity->introspect->get_attributes->{attr1}
                                         ->setval($entity, $value);

Set value of an attribute of $entity, utilizing the setter code reference retrieved via get_setter.

LICENSE AND COPYRIGHT ^

Copyright (c) 2006 the myco project. All rights reserved. This software is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO ^

Myco::Entity::Meta, Myco::Entity, CGI, Myco::Entity::Meta::Attribute::Test, Myco, Tangram, Class::Tangram, myco-mkentity

syntax highlighting: