Chapter 2. The WebTool API

The WebTool API contains a variety of functions useful to a module developer. This chapter will detail some of the more common functions, but is not intended to be an exhaustive reference. You should refer to the source code of the and modules located under /lib in your WebTool directory.

2.1. Reading and Writing Files

A very common task for WebTool modules is the reading and writing of configuration files. The WebTool API provides a read_file function accepting a file path as a parameter, returning an array of the lines in the file, and a write_file function that accepts a file path and and array of lines to write to the file.

use WebTool;

# open file and read contents into @f
my @f = WebTool::read_file("/etc/sample.conf");

# manipulate file contents stored in @f here

# write file back based on new contents of @f
WebTool::write_file("/etc/sample.conf", @f);