Properties and default values.

Although PRIMA classes have large number of properties, it is not necessary to specify values of most of them -- the defaults will do. But sometimes an inherited class needs to override the default values of its superclass. To further complicate things, there is a certain overlapping in the meaning of properties. For example, a size and a position of a widget can be specified in several ways:

   rect => [ 10, 10, 100, 100]  or
   size => [ 90, 90], pos => [ 10, 10] or
   left => 10, right => 100, bottom => 100, top = 100

PRIMA manages these details by providing two methods with most of the classes: profile_default and profile_check_in. profile_default should return an anonymous hash with default values for all properties of a given class. When the class adds some new properties and/or wishes to supply different default values for some other properties of its parent class, it overrides profile_default method. During object creation, the programmer-supplied properties are merged with properties returned by profile_default. But before this step, profile_check_in is invoked. Its job is to remove any ambiguity resulting from overlapping in the meaning of properties mentioned above, and make other transformation of properties values as necessary. This mechanism is flexible enough even to handle system-defined default values, like those queried from the X resource manager.

Properties of objects can also be set (and queried) during object's lifetime. PRIMA supports three ways of setting properties after object creation. First, properties can be bulk-set by calling method set. Just like a constructor create, set takes property name/property value pairs. Second, every property has a correspondent method set_propertyname. Third, as a convenient shortcut, a method with the same name as a property can be used. Such methods, when called without any parameters, are also good for getting properties values. Another way of getting a value of a property is to call a get_propertyname method. There is no bulk-get method.

The most complex property PRIMA classes deal with is a font. It is a hash (more precisely, a hash reference) with several allowed key names like name, size and height. During object creation, a Prima::Drawable::profile_check_in takes care of merging the default font hash with specified one. Convenience method font returns an instance of stand-alone class Prima::Font, so that things like

   $btn-> set_font( 
      { %{ $btn-> get_font }, size => 18}
   );

become just

   $btn-> font-> size( 18);

The name property of any Prima::Component serves two purposes. First, it determines an instance name of an object to do resource manager database lookups. Second, it provides an easy way to refer to child components: if an unknown method of a component is called, Prima::Component::AUTOLOAD tries to find a child component with the name of a method. This makes possible constructions like this:

   $w-> OKButton-> enabled( 0);

Of course, it is also possible to get a list of all children.