Download the bsfperl.jar from and put it into the WEB-INF/lib directory of your webapp. If you want to rebuild your Cocoon you should copy it also to the lib/local directory of your Cocoon sources, otherwise the JAR will be lost after the build.

Add the "script" generator to your sitemap and register the BSFPerl engine with BSF

  <map:generator name="script"
      <language name="perl" src="net.sourceforge.bsfperl.PerlEngineImpl">

Add a match which calls the script generator to your sitemap

<map:match pattern="">
  <map:generate src="" type="script">
    <map:parameter name="userName" value="Perl Lover"/>
  <map:serialize type="xml"/>

Perl script (

use strict;

# a bean scripting framework object, 
# $bsf, is provided to us by bsfperl.

#get the output String buffer
my $bsf_output = $bsf->lookupBean("output");

#get the Parameters object
my $bsf_parameters = $bsf->lookupBean("parameters");

#get the value of the parameter "key" defined in the sitemap
my $username = $bsf_parameters->getParameter("userName");

#generate xml
$bsf_output->append("<xml>" . "Hello, " . $username . "!" . "</xml>");

(tested with 2.1.8)

See Also

PerlScriptGenerator (last edited 2009-09-20 23:42:17 by localhost)