Next Previous Contents

5. How to write...

5.1 ...pages

In pages (.pg) you can use directives as described in previous chapters. But you can use following variables, too:

%g

Global hash which is often used for transporting values between action and page. Be careful, its validity is limited by one masser cycle (which means that it's cleared after processing all actions and pages in one request).

So you cannot use it to remember values between two requests (you cannot know which masser will process request if there is running more than one). You must use HTML and/or HTTP ways to do it (hidden fields, cookies). See persistent hash described in next text.

While coding you can use G(item) form, so print G(name); and print $g{'name'}; are equal.

%p

Global hash. Main difference from %g is its persistence between requests. You can use it mainly for data filled to it in init action or to remember some value between two masser cycles (request process).

Be careful, this is very limited in case masser is running as more than one instance (fast-cgi technology enables this and it's very useful). No one can say you, what masser instance (process) will get next request. This hash is persistent only in one instance of masser!

Be careful while using this variable, it's not intended to store large pieces of data.

You cannot use it to send information between two applications even in one masser instance, every application has its own hash.

%txt

This hash contains texts loaded from language file according to selected language (LANG variable). Read only (changes will be dropped after processing request).

%conf

This hash contains configuration read from <app>.conf. Read only (changes will be dropped after processing request).

$app

This variable contains actual application (as param('APP')).

$pg

This variable contains actually running page (as param('PG')).

$lang

This variable contains actually selected language (as param('LANG'));

$db, $db1, $db2, $db3, $db4, $db5

These variables contain DeltaX::Database objects numbered according to application configuration (see dbX_* parameters). Note: $db = $db1.

You can use following functions in your code:

error, warn, info, debug, trace

Functions from DeltaX::Trace, used for printing messages to application log.

break_page

This function allows you to change page, which is processed by masser (value of $pg and param('PG'), but you cannot do this by changing these values).

The only parameter of this function is new page name. Masser then does this:

It's used for example for switching to another page (for example error showing page) in case insufficient grants are detected or so.

Remember that everything, what was printed till calling this function, cannot (and is not) be undone.

Other useful notes:

5.2 ...actions

You can use everything (except break_page) as in pages here (see previous chapter). I only want to recommend here to use actions for doing some work and pages for printing output. It's not technical but logical difference. There are situations in which it probably cannot be done, but at least try to do it.

5.3 ...modules

Modules for masser are in fact same as "classic" perl modules. There are only two differences: You can place it outside perl lib directory (but masser must find it) and you can use some variables from masser (they are %conf, %txt, %g, %p, $app, $pg, $lang, $db, $dbX) this way:


package xy;
...
use vars qw/%txt %conf $app/;
import main;
...

5.4 ...JavaScript and CSS

I only want to discuss here using GLB(...) for inserting information from global hash %g: You must remember that this replacement is done in function page_start, so this hash (or at least keys used in javascript or css files) must be filled before calling page_start() (so calling function which fills it, include, module or code which fills it) must be placed before its calling.


Next Previous Contents