Output

From KallestadWiki

Jump to: navigation, search

Contents

Overview

The Kallestad Development Framework supports several output options that can be achieved according to any given request. The output mechanism is designed to support any number of application integration techniques. The following output mechanisms are available:

  • Text
  • HTML
  • JSON
  • XML
  • File
  • Hook

Output Options

Text Output

Text Output is generally useful for troubleshooting or running KDF from the command line.

Text output assumes that the $output is being set directly and not $outobj (maybe append Dumper($outobj) to output... hmmm...)

HTML Output

HTML Output is enabled via Templates. With Perl, this is accomplished with the module HTML::Template. The templating mechanism is relatively simple so that templates are easily interpreted by web developers without having to learn yet another template environment. This makes things easier as well when porting the KDF to different languages other than Perl.

See the following page for information on the templating system: HTML Templates

JSON Output

JSON - or JavaScript Object Notation is natively consumed by web browsers and is supported as an interpreted data structure quite easily within most web-focused languages (i.e. Java, Ruby, PHP, etc.)

JSON Output is currently handled by the JSON module, but I am eyeing towards the faster JSON::PC, JSON::XS or JSON::Syck modules, but currently I'm shying away from the C based modules because of the fact that they imply more responsible management of the string sizes. (JSON::XS purports a 14K nested JSON object limitation due to direct interaction with the stack, whereas KDF should easily handle 32K text fields) JSON::XS is about 65 times as fast as JSON, so there is a desire to work out a way to either update the code or to manage interaction with that module.

XML Output

Personally, I'm not very much a fan of XML, but there are instances where XML is quite useful and sometimes is the only option.

File Output

File Output is useful for publication of documents, and really should be used as a peripheral output mechanism in combination with other output methodologies.

Hooked Output

If the natively provided output options are not appropriate for a given situation, hooks are provided to enable additional output mechanisms via the API (for instance if a third party proprietary data structure is necessary, or if there are conflicts with the way KDF manages JSON or XML output)

HTTP Headers

HTTP Headers are always sent on output.

If the KDF receives a 'jsreturn' parameter, that parameter will be returned as an X-Json header. This is useful if you want to maintain tracking keys for individual ajax requests.

The framework provides the set_header function as part of the KDF::Output object. This function takes two parameters - the name of the header, and the value of the header.

This function is not to be used for cookies at least for now (as only the last cookie set would actually get sent to the browser). The same holds true for any header which would require multiple outputs.

Output Objects vs. Output Text

The KDF::Output object contains two important variables - outobj and output. (The output method is KDF::Output->out())

The outobj is translated into a JSON string, an XML string, or an HTML template as necessary. This translation replaces the output variable.

Kallestad Development Framework Topics

Personal tools