Entity Introduction : A More complex Application
Previous: Getting Started.
Next: ENode API

6. A More complex Application

To really excercise some entity, we're going to make an application that modifies its own structure.

Here's the XML:


<object name="foo">
  <window title="This app rules">
    <button label="DO NOT CLICK ME" onclick="perl:clicked"/>
  </window>
  <?perl
    sub clicked
    {
      $the_button = shift;
      print "button $the_button was clicked\n";
      $the_button->attrib("label" => "I TOLD YOU NOT TO CLICK ME");
      $xml_to_be_appended = qq!
        <window title="This app still rules">
          <button label="REALLY, DO NOT CLICK ME" onclick="perl:clicked"/>
        </window>
!;
      $the_button->append_xml($xml_to_be_appended);
    }
  ?>
</object>

Now every time a button is clicked, this button-node has its "label" attribute changed, and a small XML tree is appended to the button-node. The appended XML becomes a child of the button-node and consists of a window-node which in turn has another button-node as its child. This new button can then be clicked, which calls the "perl:clicked" callback, which then changes the label and appends another small XML tree... and so on ad infinitum.

Note in this case that the same perl callback function can be used any number of times with various entity events (in this case, with "onclick" events from various buttons). Notice, also, that entity dynamically re-renders changed attributes and new nodes.


Entity Introduction : A More complex Application
Previous: Getting Started.
Next: ENode API