WebMake Documentation (version 1.1)

The <{perl}> Directives

Arbitrary perl code can be executed using this directive.

It works like perl's eval command; the return value from the perl block is inserted into the file, so a perl code block like this:


	<{perl
	  $_ = '';
	  for my $fruit (qw(apples oranges pears)) {
	    $_ .= " ".$fruit;
	  }
	  $_;
	}>

will be replaced with the string " apples oranges pears". Note that the $_ variable is declared as local when you enter the perl block, you don't have to do this yourself.

If you don't like the eval style, you can use a more PHP-like construct using the perlout directive, which replaces the perl code text with anything that the perl code prints on STDOUT, like so:


	<{perlout
	  for my $fruit (qw(apples oranges pears)) {
	    print " ", $fruit;
	  }
	}>

<{perl}> sections found at the top level of the WebMake file will be evaluated during the file-parsing pass, as they are found.

<{perl}> sections embedded inside content chunks or other tagged blocks will be evaluated only once they are referenced.

Perl code can access content variables and URLs using the library functions provided.

The library functions are available both as normal perl functions in the default main package, or, if you want to write thread-safe or mod_perl-safe perl code, as methods on the $self object. The $self object is available as a local variable in the perl code block.

A good example of perl use inside a WebMake file can be found in the news_site.wmk file in the examples directory.

WebMake Documentation (version 1.1)