Fri Oct 8 01:11:47 2004
AxKit XSP Tag LibrariesIntroductionTag libraries are ways to hide code behind XML tags. They are how you prevent your XSP pages from becoming a morass of perl code interspersed with a bit of XML for the output (which is what you see with many PHP or ASP pages). Tag libraries range from the very simple (e.g. the "Param" taglib) to the complex (e.g. the "PerForm" taglib) to completely application specific tag libraries (such as the Wiki taglib that runs this Wiki). How a taglib worksWhen an XSP page is compiled AxKit uses a SAX processor to turn that page into perl code (the perl code in turn generates the XML output at runtime). By creating a taglib you change how the SAX processor works - when it sees tags in your namespace it switches control to your module, so your taglib can insert its own custom code into the output. This may sound complex but and writing perl code this way can prove difficult, but there are a few ways to simplify programming taglibs that make it as simple as writing a perl module. Custom or CPAN taglib?There are many taglibs on CPAN already for things like session management, form processing, and cookie access, but there is nothing mandating that you shouldn't write your own. Generally when people ask if they should write their own or not the answer is one of how they like to work. The taglibs on CPAN tend to be highly generic - low level operations like accessing cookies or sessions or even doing forms. However you may wish to hide all of that operation behind a few custom tags that look something like: <fengu:initialize/> <fengu:display page="display"/> All of this is possible with taglibs. Loading taglibsBefore you use a taglib you have to tell AxKit about it by loading it. Doing this is very simple: AxAddTaglib AxKit::XSP::Param This loads the module <param:action xmlns:param="http://axkit.org/NS/xsp/param/v1"/> CPAN TaglibsThe following taglibs are available on CPAN: ParamThe param taglib is a simple way to access querystring or form parameters in your XSP page. Usage is very simple, just use the namespace prefix followed by the name of the single-valued parameter you wish to access: <!-- get the "foo" parameter --> <param:foo/> Note though that this is restricted to single valued parameters - there is no facility to access parameters with multiple values. Also note that the parameter name is restricted to valid XML LocalNames. PerFormThe perform taglib is one of the more complex taglibs on CPAN. It is designed to be a complete solution for creating and processing forms - hence the reason its so complex. Edit This Page / Show Page History / |

Home