The LiveAPI Perl Module provides an environment for Perl applications. You can find this Perl module in the
/usr/local/cpanel/Cpanel/LiveAPI.pm file. An example ships with cPanel & WHM as the
- Perl applications that use the LiveAPI Perl module must instantiate the
- Perl scripts' filenames must end in either the
- Save files to the
themeis the cPanel theme, or create a symlink to the appropriate files.
The following example script uses the LiveAPI Perl module to call the
Line 4 instantiates the
Cpanel::LiveAPI object. This ensures that the script or application uses the LiveAPI Perl module. For more information, read the perldoc.perl.org perlobj documentation.
Connect to cPanel & WHM
Line 7 uses the LiveAPI
new() method to connect to cPanel & WHM. For more information, read our LiveAPI Methods documentation.
- You must include this line in all LiveAPI Perl code.
- Only include this line once in any file.
Call cPanel & WHM API functions
Lines 10 through 15 use the
uapi() method to call the
UAPI function, and assign the function's output as a hash reference to the
- You can call multiple functions in a single file.
- For more information and use examples, read that function's documentation. All cPanel API 1, cPanel API 2, and UAPI function documents include specific examples for the LiveAPI Perl module.
Perform the desired actions
Your script or application's actions could combine any of Perl's many functions. Often, this includes the following actions:
- Validate data.
- Sanitize data (for example, use the
chomp()function to remove trailing newlines).
- Check data in other files.
- Write data to other files.
Disconnect from cPanel & WHM
Line 19 uses the
end() method to deconstruct the
Cpanel::LiveAPI object and close the connection to cPanel & WHM. For more information, read our LiveAPI Methods documentation.
You must close the connection to cPanel & WHM at the end of LiveAPI scripts and applications.