Don't trust __PACKAGE__, as it is broken on older Perl versions
authorJamie Cameron <jcameron@webmin.com>
Thu, 5 Mar 2009 21:36:04 +0000 (21:36 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 5 Mar 2009 21:36:04 +0000 (21:36 +0000)
WebminCore.pm
web-lib-funcs.pl

index 427d13c..82ced40 100644 (file)
@@ -32,6 +32,7 @@ push(@EXPORT, qw(&theme_post_save_domain &theme_post_save_domains &theme_post_sa
 if ($] <= 5.008004) {
        print STDERR "WARNING: Webmin needs Perl version 5.008004 or later!\n";
        }
+$called_from_webmin_core = 1;
 require "web-lib.pl";
 require "ui-lib.pl";
 
index 5901701..dca5c8c 100755 (executable)
@@ -8487,11 +8487,12 @@ sub get_module_variable
 {
 my ($v, $wantref) = @_;
 my $slash = $wantref ? "\\" : "";
-if (__PACKAGE__ eq 'WebminCore') {
+my $thispkg = &web_libs_package();
+if ($thispkg eq 'WebminCore') {
        my ($vt, $vn) = split('', $v, 2);
        my $callpkg;
        for(my $i=0; ($callpkg) = caller($i); $i++) {
-               last if ($callpkg ne __PACKAGE__);
+               last if ($callpkg ne $thispkg);
                }
        return eval "${slash}${vt}${callpkg}::${vn}";
        }
@@ -8531,13 +8532,24 @@ sub callers_package
 {
 my ($fh) = @_;
 my $callpkg = (caller(1))[0];
+my $thispkg = &web_libs_package();
 if (!ref($fh) && $fh !~ /::/ &&
-    $callpkg ne __PACKAGE__ && __PACKAGE__ eq 'WebminCore') {
+    $callpkg ne $thispkg && $thispkg eq 'WebminCore') {
         $fh = $callpkg."::".$fh;
         }
 return $fh;
 }
 
+# web_libs_package()
+# Returns the package this code is in. We can't always trust __PACKAGE__
+sub web_libs_package
+{
+if ($called_from_webmin_core) {
+       return "WebminCore";
+       }
+return __PACKAGE__;
+}
+
 $done_web_lib_funcs = 1;
 
 1;