The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Myco::Entity::Meta::Attribute::UI

SYNOPSIS

 # For typical construction see

Myco::Entity::Meta::Attribute

 # Retrieving from entity attribute metadata
 #   (for fictional attribute 'clue')
 $ui_meta = $entity->introspect->get_attributes->{clue}->get_ui;

 # Attribute access
 $label = $ui_meta->get_label;
 $options = $ui_meta->get_options;
 $suffix = $ui_meta->get_suffix;
 $suffix = $ui_meta->get_suffix;
 $widget_specification = $ui_meta->get_widget;

 # Widget closure
 #   creation ( happens automatically via set_widget() )
 $ui_meta->create_closure;

 #   usage
 my $cgi = CGI->new;
 print $ui_meta->get_closure->( $cgi, $entity_attribute_value,
                                formname => 'fooForm',
                                %CGI_method_params );

DESCRIPTION

Container for metadata describing and facilitating appropriate user interface behavior for an entity class attribute.

This class is designed such that each of its objects normally has a "part-of" relationship with an object of class Myco::Entity::Meta::Attribute.

COMMON ENTITY INTERFACE

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

Extended Constructor Behavior

If the constructor (new()) is called without a widget parameter then a default value for the corresponding attribute is automatically established.

The constructor is not normally called directly, rather, it is called during attribute metadata definition via calls to method add_attribute() of class Myco::Entity::Meta::Attribute. As such, this extended behavior is more fully documented in the description of the ui attribute of said class.

ATTRIBUTES

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

  • Set attribute value

     $obj->set_attribute($value);

    Check functions (see Class::Tangram) perform data validation. If there is any concern that the set method might be called with invalid data then the call should be wrapped in an eval block to catch exceptions that would result.

  • Get attribute value

     $value = $obj->get_attribute;

Attributes belonging to this class that are interest to the typical developer are documented in the description of the ui attribute of class Myco::Entity::Meta::Attribute.

A listing of other available attributes follows:

attr

 type: ref   required:  not undef

Utilitatrian attribute that stores the reference to the Myco::Entity::Meta::Attribute object of which this object is a "part".

do_query

 type: int

Boolean value (1 | 0) that flags an attribute of type 'ref' to be included in UI generation, providing a way for Myco::UI::MVC::Controller to hook into Myco::Query, to search for a 'ref' attribute.

 type: int

Boolean value (1 | 0) that flags an attribute of type 'ref' to be included in UI generation with a popup_menu of object IDs/display names. Used primarily by Myco::UI::MVC::Controller.

iset_box

 type: int

Name of a Myco class that flags an attribute of type 'iset' to be included in UI generation via a box of object IDs/display names. Used primarily by Myco::UI::MVC::Controller.

ADDED CLASS / INSTANCE METHODS

create_closure

 $instance->create_closure;

Causes the creation of an anonymous subroutine capable of creating a user interface element for the entity object attribute described by this ::Attribute object. The anonymous subroutine is a closure containing all relenvant user-interface related attribute metadata (from ::Attribute::UI: 'widget', 'label'; from ::Attribute: 'values', 'value_labels', etc. See ATTRIBUTES section from both classes). The subroutine code reference is saved via a call to $instance->set_closure.

The generated closure leverages a method from CGI.pm to do the actual user interface element generation. The closure may be called as illustrated below

 $instance->get_closure->($CGI, $value, -name=>$attr_name, %params);

...where $CGI is a CGI.pm object and %params are valid parameters for the CGI.pm method being employed (in addition to those already stored in the closure).

It should be possible, in the future, to generalize this mechanism to work in other (non HTML) user interface contexts (eg. Perl/Tk, curses).

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::Attribute::UI::Test, Myco::Entity::Meta::Attribute, Myco::Entity, Myco, Tangram, Class::Tangram, myco-mkentity