<cpanel> or <?cp > tags. Your application will also process and run much faster.
Cpanel:: namespace are available.
If you need to install additional modules, you can place them in:
init(). This function will only need to return output, but it is required in order for the API1 call to work successfully.
The function should resemble the following:
sub Module_init {
return;
}
In the example above, Module represents the module name you wish to use.
Once you have set up the required function, you can use your module to print or return data. However, if you are returning more than a string, you will need to use API2.
A sample function within a cPanel module can be found below. This module simply prints data to the cPanel interface:
sub Module_test {
print “testing 1 2 3”;
}
@_ variable. You can assign $_[array index] to any given variable if you wish to pass parameters to a human-readable variable. For example:
sub Module_printLC {
my ($string1) = @_;
print lc( $string1 );
}
If, for example, you wish to pass the <cpanel> tag, you could do so by including:
The example above would print<cpanel Module=”printLC(TESTING)”>
testing to the cPanel interface.
sub Module_raiseError {
$Cpanel::CPERROR{‘module’} = “This is an error message”;
}
In the example above, module represents the module name you wish to use.
The example above would allow you to check for the existance of an error using a <cpanelif> tag. This can be printed and check in the interface by using $CPERROR{'module'} inside your HTML file.
api2() within the module. This function specifies which API2 calls are mapped to which functions. It is also responsible for returning a hash that contains information on how the module works. There are only 2 elements of this hash that need to be returned:
api2() function can be found below:
sub api2 {
my $func = shift;
my %API;
$API{‘functionName’}{‘func’} = “api2_test”;
$API{‘functionName’}{‘engine’} = ‘hasharray’;
return \%{ $API{ $func } };
}
Since the API2 system uses named prameters, the @_ variable will need to be assigned to a hash like so:
sub api2_test {
my %OPTS = @_;
}
%OPTS hash for API2 input parameters.
Once you have created this function within your cPanel module, any data passed to the function within a <?cp ?> tag can be accessed as an element of that hash. As an example, assume the <?cp ?> tag has been passed the following information:
In this example, after<?cp Module::test( %, data, ) number=”5” ?>
%OPTS has been properly assigned, you will be able to access the number variable via $OPTS{'number'};. For example:
sub api2_test {
my %OPTS = @_;
my $number = $OPTS{‘number’};
}
<?cp ?> tags. Elements within the returned reference must either be arrays of hash references or scalar variables.
{
key => “value”
}
In the example above, key can be accessed via the <?cp ?> tags when laid out like so:
The example above will print value when accessed via a web browser.<?cp Module::function( %, key, ) ?>
[
{
key => “value1”
},
{
key => “value2”
}
]
In the example above, the template will be applied to each element of the array when calling API2 functions via the <?cp ?> tags. In this particular scenario:
The example above, when given an array of hashes, will display the following:<? Module::function( % [br /], key, ) ?>
value 1
value 2
{
element => [
{
key => “value1”
},
{
key => “value2”
}
]
another_element => “testing”
}
In order to call this data using <?cp ?> tags, you would need to use the following format:
<?cp Module::function(
% [br /]%,
another_element,
element:: KEY-${key}[br /]:
)
?>
The example above would output the following:
testing
KEY-value1
KEY-value2
Copyright © cPanel 2000-2010.