-
Notifications
You must be signed in to change notification settings - Fork 1
Type
-
Provide meta-data to models and widgets
-
Map perl values to and from external formats: SQL, HTML, XML, etc.
-
Provide functions for comparison, arithmetic, etc.
-
Extensive test cases.
-
Common base class: Bivio.Type
from_literal() -- validate and parse a value from user input, often overridden by subclass
to_literal() -- simple formatting a value for presentation to the user
from_sql_value() -- parse a value from the database, rarely overridden
to_sql_value() -- convert a value to the database representation
to_html()
to_uri()
to_xml()
compare()
As an exception to the general rule that types are function libraries, each value in an enum is an object instance.
Enums can be a task item. Calling execute() on an enum puts the value on the request with the "Type.<Enum Class>" key.
Enum values automatically generate certain convenience methods. For example, the Gender Enum defined below:
__PACKAGE__->compile([
UNKNOWN => [0],
FEMALE => [1],
MALE => [2],
]);will have additional methods defined based on the enum values:
my($value) = ...;
// shortcut for Bivio::Type::Gender->equals(Bivio::Type::Gender->FEMALE)
if ($value->eq_female) {
....
} // shortcut for Bivio::Type::Gender->MALE->execute($req);
Bivio::Type::Gender->execute_male($req)Enums can delegate some or all of their values to the application by deriving from Type.EnumDelegator. For example the Bivio::Auth::Role (or Auth.Role) module defines its Enum values in Bivio::Delegate::Role which most applications will override to provide application specific role.
Type classes derive from a common Type base class and may form a hierarchy, below is a sample.
(Click for larger view)
- Agenda
- Getting Started
- My-Status Example Application
- Model
- View
- Task
- Application Support
- Testing
- Miscellaneous