UR::Object::View(3pm) | User Contributed Perl Documentation | UR::Object::View(3pm) |
UR::Object::View - a base class for "views" of UR::Objects
$object = Acme::Product->get(1234); ## Acme::Product::View::InventoryHistory::Gtk2 $view = $object->create_view( perspective => 'inventory history', toolkit => 'gtk2', ); $widget = $view->widget(); # returns the Gtk2::Widget itself directly $view->show(); # puts the widget in a Gtk2::Window and shows everything ## $view = $object->create_view( perspective => 'inventory history', toolkit => 'xml', ); $widget = $view->widget(); # returns an arrayref with the xml string reference, and the output filehandle (stdout) $view->show(); # prints the current xml content to the handle $xml = $view->content(); # returns the XML directly ## $view = $object->create_view( perspective => 'inventory history', toolkit => 'html', ); $widget = $view->widget(); # returns an arrayref with the html string reference, and the output filehandle (stdout) $view->show(); # prints the html content to the handle $html = $view->content(); # returns the HTML text directly
Producing a view object does not "render" the view, just creates an interface for controlling the view, including encapsualting its creation.
The subject can be set later and changed. The aspects viewed may be constant for a given perspective, or mutable, depending on how flexible the of the perspective logic is.
(Note: see UR::Object::View::Toolkit::Text for details on the "text" widget, used by HTML/XML views, etc. This is just the content and an I/O handle to which it should stream.)
The following three properties are constant for a given view class. They determine which class of view to construct, and must be provided to create().
These methods control which object is being viewed, and what properties of the object are viewed. They can be provided at construction time, or afterward.
An "aspect" is some characteristic of the "subject" which is rendered in the view. Any property of the subject is usable, as is any method.
When writing new view logic, the class name is expected to follow a formula:
Acme::Rocket::View::FlightPath::Gtk2 \ / \ / \ subject class name perspective toolkit
The toolkit is expected to be a single word. The perspective is everything before the toolkit, and after the last 'View' word. The subject_class_name is everything to the left of the final '::View::'.
There are three methods which require an implementation, unless the developer inherits from a subclass of UR::Object::View which provides these methods:
This should be implemented in a given perspective/toolkit module to actually create the GUI using the appropriate toolkit.
It will be called before the specific subject is known, so all widget creation which is subject-specific should be done in _bind_subject(). As such it typically only configures skeletal aspects of the view.
This method has a default implementation which does a general subscription to changes on the subject. It probably does not need to be overridden in custom views. Implementations which _do_ override this should take an undef subject, and be sure to un-bind a previously existing subject if there is one set.
The toolkit class related to a view is responsible for handling show/hide logic, etc. in the base UR::Object::View class.
Returns the name of a class which is derived from UR::Object::View::Toolkit which implements certain utility methods for views of a given toolkit.
$o = Acme::Product->get(1234);
$v = Acme::Product::View::InventoryHistory::HTML->create(); $v->add_aspect('outstanding_orders'); $v->show;
2022-01-17 | perl v5.32.1 |