View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jakub Špičák > deltax-modules-3.14 > DeltaX::Page



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 1.3   Source   Latest Release: deltax-modules-3.17


DeltaX::Page - Perl module for parsing pages for masser

    /     \ _____    ______ ______ ___________
   /  \ /  \\__  \  /  ___//  ___// __ \_  __ \
  /    Y    \/ __ \_\___ \ \___ \\  ___/|  | \/
  \____|__  (____  /____  >____  >\___  >__|
          \/     \/     \/     \/     \/        project


 use DeltaX::Page;

 my $page = new DeltaX::Page('');
 if (!$page->compile()) {
  # write some error
 else {
  my $code = $page->{translated};



Constructor. It has one required parameter - name of file to parse. This name can be prefixed with string: so module it uses as code itself, without reading the file.

Other parameters are in "directive => sub reference" form (see "DIRECTIVES").

You can define values for conditional output as an array reference to _defs argument to new() this way:

 my $page = new DeltaX::Page('', dir1=>\&dir,
  _defs=>['defined1', 'defined2']);


Tries to compile given file to perl code (which can be evaled). See "FILE SYNTAX" for more information. Returns true in case of success, otherwise returns false.


Returns textual representation of error (only valid after compile() call).


This module is parsing page code for masser (see - it's something like perl code embeded in HTML (or XML or other) code. It compiles everything to print statements, except this:


 Source code:
  <?- this is a test -?>
  <h1>Hi, welcome to <?=$app_name?>!</h1>
    my (undef, undef, undef, $day, $mon, $yer) = localtime();
    $mon++; $yer+=1900;
    print sprintf("%02d.%02d.%04d", $day, $mon, $yer);
  See you later...
 Compiled code:
  print "<h1>Hi, welcome to ";
  print $app_name;
  print "!</h1>";
  print "\n\n";
  print "It's\n";
    my (undef, undef, undef, $day, $mon, $yer) = localtime();
    $mon++; $yer+=1900;
    print sprintf("%02d.%02d.%04d", $day, $mon, $yer);
  print "\n<br/>\nSee you later\n";

  [code was made a little bit readable :-)]


Everything in <?!directive [arguments]?> is a special directive. Module knows these directives:


<?!include file?> - includes given file, this means tries to read and compile this file and (in case of success) includes resulting code into actual code.


<?!package file?> - works as include

everything other

Every other directive must be defined in new() function and apropriate function will be called (arguments will be given to this function - if there are any). Everything which is returned by this function is included in the code (function must return true value - at least one space, if it returns false, it is detected as an error).

You can define directive in new() for include and package too, but this doesn't change include or package itself, but module expects that called function returns real full path to file to be included. Other returned values are got as additional defines for conditional instructions (see _defs in new()) - but only for included file.

There is special directive definition *, which means 'everything other', so if undefined directive is found, function assigned to it will be called.


 sub my_include {
  my $filename = shift;
  # only relative path
  return substr($filename, rindex($filename,'/')+1);

 sub my_javascript {
  my $javascript_name = shift;
  # code to give someone know that JavaScript code must be generated...
  return "$cgi->add_javascript('$javascript_name');";

 sub my_other {
        my ($directive, @args) = @_;
        # return code according to $directory
 my $page = new DeltaX::Page('',include=>\&my_include,
  javascript=>\&my_javascript, '*'=>\&my_other);
syntax highlighting: