TL;DR:
Are developers meant to use the methods in Cpanel::App to determine which environment/application their plugin is running in?
Longer -
I'm (slowly) developing a cPanel plugin and wanting to check which "application" the user is in (cpanel, whm, etc) - and the Perl package
Here's my test code:
I did try accessing
Are developers meant to use the methods in Cpanel::App to determine which environment/application their plugin is running in?
Longer -
I'm (slowly) developing a cPanel plugin and wanting to check which "application" the user is in (cpanel, whm, etc) - and the Perl package
Cpanel::App
appears to do what I want (with methods such as is_cpanel
, is_webmail
, is_whm
and with a POD which says:However, whenever I load the Cpanel::App package, it sets the internal variableThis module provides authoritative logic for determining whether the
running cpsrvd application is cPanel, WHM, or Webmail.
You should NOT access global scalars like$Cpanel::appname
to
discern this information; use this module’s functions instead.
$appname
to "cpanel
" and so only is_cpanel
comes back true no matter which application is running.Here's my test code:
Code:
#!/usr/local/cpanel/3rdparty/bin/perl
# File location: /usr/local/cpanel/whostmgr/docroot/cgi/test.cgi
use strict;
use warnings;
use Cpanel::App();
print "Content-type: text/html; charset=utf-8\r\n\r\n";
print 'App name normalised: ' . Cpanel::App::get_normalized_name() . "<br>\n";
print 'Are we whm? ' . ( Cpanel::App::is_whm() ? 'yes' : 'no' ) . "<br>\n";
print 'Are we cpanel? ' . ( Cpanel::App::is_cpanel() ? 'yes' : 'no' ) . "<br>\n";
print 'Are we webmail? ' . ( Cpanel::App::is_webmail() ? 'yes' : 'no' ) . "<br>\n";
exit 0;
$Cpanel::App::appname
directly without loading Cpanel::App
, but then it was empty. Quite a lot of Cpanel provided code accesses $Cpanel::appname
(114 mentions) and $Cpanel::App::appname
(84 mentions) - with only 13 mentions of Cpanel::App::is_whm
and 5 mentions of Cpanel::App::is_cpanel
,...