Skip to content

Perl API

David Jeske edited this page May 17, 2017 · 4 revisions
########################
# ClearSilver::HDF

$hdf = ClearSilver::HDF->new()         # creates a new HDF dataset object.
$hdf->readFile(STRING:$filename)       # reads the contents of an on-disk HDF dataset into the current HDF object.

# getValue() retrieves a string value from the HDF dataset. The $hdfpath is a dotted 
#    path of the form "A.B.C".
my $str_value = $hdf->getValue(STRING:$hdfpath,STRING:$default_value)

# setValue() adds a string value to the HDF dataset.
$hdf->setValue(STRING:$hdfpath,STRING:new_value)

# sortObj() allows you to retrieve an HDF subtree in sorted order, using your sort 
#    function to determine the order.
$hdf->sortObj(STRING:$sort_function_name)

# getObj() allows you to retrieve the HDF object which represents the HDF subtree ad
#      the named $hdfpath.
$hdf->getObj(STRING:$hdfpath)

# objName() retrieves the name of the current HDF node. The name only includes the
#      current level.
my $str_name = $hdf->objName();

# 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();

# objValue() retrieves the value of the current HDF node. Here is a sample code snippit:
$hdf->objValue();

# For Example:
  $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();

# objChild() 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->objChild();
$hdf->objNext();
$hdf->getChild();

###############################
# Clearsilver::CS

# CS->new() 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 = Clearsilver::CS->new(HDF:$my_hdf)

# parseString() parses the provided string template fragment into the parse tree.
$cs->parseString(STRING:$cs_code_string)


# parseFile() parses the provided template file into the parse tree.
$cs->parseFile(STRING:$cs_filename)

# render()  evaluates the parse tree and produces the rendered output as a string.
my $string = $cs->render();

Clone this wiki locally