Skip to content

Perl API

Here is some preliminary documentation for the ClearSilver module:

$hdf = ClearSilver::HDF->new()

This method creates a new HDF dataset object.

$hdf->readFile(STRING:$filename)

This method reads the contends of an on-disk HDF dataset into the current HDF object.

my $str_value = $hdf->getValue(STRING:$hdfpath,STRING:$default_value)

This method retrieves a string value from the HDF dataset. The $hdfpath is a dotted path of the form “A.B.C”.

$hdf->setValue(STRING:$hdfpath,STRING:new_value)

This method adds a string value to the HDF dataset.

$hdf->sortObj(STRING:$sort_function_name)

This method allows you to retrieve an HDF subtree in sorted order, using your sort function to determine the order.

$hdf->getObj(STRING:$hdfpath)

This method allows you to retrieve the HDF object which represents the HDF subtree ad the named $hdfpath.

my $str_name = $hdf->objName();

This method retrieves the name of the current HDF node. The name only includes the current level. Here is a sample code snippit:

$hdf = ClearSilver:\:HDF->new();
$hdf->setValue("A.B.C","1");
$hdf_subnode = $hdf->getObj("A.B.C");
# this will print "C"
print $hdf_subnode->objName();

$hdf->objValue();

This method retrieves the value of the current HDF node. Here is a sample code snippit:

$hdf = ClearSilver:\:HDF->new();
$hdf->setValue("A.B.C","1");
$hdf_subnode = $hdf->getObj("A.B.C");
# this will print "1"
print $hdf_subnode->objValue();

$hdf->objChild();

This method is used to walk the HDF tree. Keep in mind that every node in the tree can have a value, a child, and a next peer.

$hdf->objNext();

$hdf->getChild();

$cs = Clearsilver::CS->new(HDF:$my_hdf)

This method creates a new ClearSilver template rendering context. You should have already created and populated an HDF dataset which you provide as the only argument to the constructor.

$cs->parseString(STRING:$cs_code_string)

This method parses the provided string template fragment into the parse tree.

$cs->parseFile(STRING:$cs_filename)

This method parses the provided template file into the parse tree.

my $string = $cs->render();

This method evaluates the parse tree and produces the rendered output as a string.