HomePage RecentChanges ExtJS Perl Library

NEW: See Ext.Direct

I am writing (with someone else) an ExtJS Perl back end.

Actually Two Backends:

  1. A stand alone example CGI to go with the demonstrations
  2. A library to do what you mostly need with a few lines of code

Why both: Because we want to demonstrate from scratch how to write a CGI so you can write things we have not thought of, teach some perl, and promote perl into the Ext community; and because I want to do only 1 or two lines of code to provide basic back end secure functionality for ExtJS.

Status

The CGI

Basic Requirements

The Library

Basic Requirements

Handlers

This is what the library can handle. It maps nicely to what Ext wants.

Lists

Grid, Editing with forms and Combo boxes all need to get lists of data.

Insert, Delete, Update

A single entry in a data store (such as a database).

Tree

Walking through a tree (e.g. parent/child nodes on a database, or directory listings).

Examples

Here are some examples of how it would be used.

CGI Simple List

#!Perl
use ExtJS;
my $extjs = ExtJS->new('example.db');
$extjs->list->query(q{SELECT * FROM mylist WHERE title like ? ORDER BY title});
$extjs->list->process();

Apache Module

#!XML
PerlModule ExtJS::Apache
<Location /get/mylist>
  PerlModule ExtJS::Apache
  PerlSetVar ExtJS_Database /tmp/example.db
  PerlSetVar ExtJS_Query SELECT * FROM mylist ORDER BY title
</Location>

TODO - Example showing Query written using Table Name from path info or similar.

CGI With Lucene Backend

This example uses the list code but replaces the default DBI backend with a Lucene version.

#!Perl
use ExtJS;
my $extjs = ExtJS->new();
$extjs->data('Lucene', '/tmp/lucenedemo');
$extjs->list->query(['title', 'content']);
$extjs->list->process();

Notes:

Backends

The backends being written or at least thought about.

Data Store

Read and write to the data. Just a way of abstracting to a single set of entries.

The data backend must support the following methods:

Encoder

Encode to JSON or XML or Data Dumper - anything you want really. This system will provide

This version will probably not have any options to encode.

Method: encode(hashref), return a string and content type

Output

Take the Content Type and String provided by the Encoder and output it. Default would be CGI (also support for mod_perl).

Input

Call back for input.

Method: get(key), return string

Default: CGI (also support for mod_perl)

Limitations

Plugin Structure

The model above is fantastic for writing new Input, Output, Encoding and Data storage models. But it requires multiple refactoring for adding a new Handler (like Tree). Especially "Data" which needs to know how to query its objects to return a tree (quite different to a list).

General Discussion

JSON standard

The Samples, Examples and Tutorials on the ExtJS site have no standard for reading or writing data. Some of them return simple structures like a "0" or "1" and others return a JSON object. The JSON objects have no standards either, often using the word "success" to mean a true/false flag and "failure" to contain a message. Some of the ExtJS classes use JSON directly but also do not have a standard.

Here is an attempt to start a standard JSON structure, based on many existing examples, for the use in these ExtJS tutorials and examples.

#!JavaScript
{
  // Did this work?
  success: TRUE | FALSE, 
  // TODO: How to pass a message ?
  failure: "Why it failed",
  // Results array of objects (object = Javascript Hash)
  results: [
    {
      // Although only an example object... id/title would be a standard for lists etc
      id: 123,
      title: "Hello",
    },
    {
      id: 222,
      title: "World",
    },
  ],
  // Fields, also used for order - TODO Consider how to give metadata?
  fields: [
    'id', 'title',
  ],
}

Notes:

JSON Encoding

Almost all the example code uses a mix of manually generated JSON and automatically via library encoding. These examples encourage some very poor programming technique. Often the Javascript is very well written and the backend is poorly written.

Call Standard

Calling, CGI Parameters, general location to be defined. The theory is you can cut/paste the examples and they will work without changing your system.

Re-write Examples

This is a bit of a holy grail - I would like to have well structure database, good PHP & Perl examples and Javascript to match. I have started documenting some of the changes that would be good, but not sure what time I have to complete them:

Software error:

Can't locate object method "endform" via package "CGI" at /data/scott.dd.com.au/wiki/modules/search.pl line 15.

For help, please send mail to the webmaster (webmaster@dd.com.au), giving this error message and the time and date of the error.