Christopher H. Laco
and 1 contributors


AxKit::XSP::ObjectTaglib::Demo - A demo taglib using ObjectTaglib


    AxAddXSPTaglib AxKit::XSP::ObjectTaglib::Demo

    #XSP page
    <?xml version="1.0" encoding="UTF-8"?>
    <xsp:page xmlns:xsp=""






This taglib demonstrates how to use the ObjectTaglib to map XSP tags to a set of object oriented classes based on the original examples in Apache::AxKit::Language::XSP::ObjectTaglib.



When the topmost <demo:courses> start tag is encountered, the start_course method is called. The most common implementations would probably use the start/end methods to load and map the topmost tags to the root objects being used. After that, the relationships in @specification will be used to generate the necessary code.

Let's break it down. First, we declare the sub and catch the XSP SAX model, the tag, and the attributes passed from within the <demo:courses> tag:

    sub start_courses {
      my ($e, $tag, %attr) = @_;

Next, let's turn off the XSP text output managing for a moment. I don't know why, but it had to be done to work. :-)


Now we'll create a new variable containing the code to insert into the XSP innards. First we'll load the Courses module:

      my $out = '
        use AxKit::XSP::ObjectTaglib::Demo::Courses;

Now we'll create an array and load all of the Course objects into it:

      my @_xsp_axkit_xsp_objecttaglib_demo_courses =

Take a closer look at the variable name: @_xsp_axkit_xsp_objecttaglib_demo_courses. ObjectTaglib expects certain variable names when it builds it's code for looping and calls methods on objects using the method and objects names specified in @specification. axkit_xsp_objecttaglib_demo is a safe version of the current taglib name AxKit::XSP::ObjectTaglib::Demo. courses is the root courses object declared within the @specification as:

    tag    => 'courses',
    type   => 'special',
    start  => \&start_courses,
    end    => \&end_courses

If we declared a count tag with a target of courses

    tag    => 'count',
    target => 'courses'

target is appended to the base variable name, and it's method count is called. That looks something like this $_xsp_axkit_xsp_objecttaglib_demo_courses->count.

But I digress, back to our program. Next, we setup a looping mechanism wrapped around all of our other tags:

      for my $_xsp_axkit_xsp_objecttaglib_demo_course
        (@_xsp_axkit_xsp_objecttaglib_demo_courses) {


We left of the second half of that loop closure. We'll add that when end_courses is called after everything else is processed.

      return $out;


When </demo:courses> is encountered, end_courses is called. There isn't anything too exciting here. Like before, we declare the sub and catch the tag info:

    sub end_courses {
      my ($e, $tag, %attr) = @_;

Again, we'll turn of text management just because.


Lastly, we'll write out the main courses loop closure and return it.

      my $out = '

      return $out;




    Christopher H. Laco