You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Enrico Sorcinelli <e....@pisa.iol.it> on 2002/03/08 14:01:15 UTC

Apache::Status override keys in menu_item() sub

Hi all,
I've seen that there is a conflict situation in Apache::Status module 
(v 2.02, mod_perl 1.26) in handling plug-in items.
In effect when I install an Apache::Status menu item plug-in, there isn't 
control over pre-installed items.
For example I can add following item in my module:

# prepare menu item for Apache::Status
Apache::Status->menu_item(
   'inc' => 'Overriding Apache::Status menu item',
   sub {
      my($r, $q) = @_;
      my(@s) = "<HR>My dump...</HR>";
      return \@s;
   }
) if ( $INC{'Apache.pm'} && Apache->module('Apache::Status') );  

In this way, I will override the %status hash entry corresponding to 
'Loaded Modules'.
Any chances to patch this by checking existent items before typeglobbing?

This is a _very simple_ proposal patch:

---CUT HERE---
--- Status.pm   Fri Mar  8 13:11:05 2002
+++ Status.pm-patched   Fri Mar  8 13:10:55 2002
@@ -45,6 +45,12 @@
 
 sub menu_item {
     my($self, $key, $val, $sub) = @_;
+
+    if ( defined $status{$key} ) {
+        print STDERR "Apache::Status:    key '$key' already defined! Plug-in installation skipped\n";
+        return;
+    }
+
     $status{$key} = $val;
     no strict;
     *{"status_${key}"} = $sub 
---CUT HERE---

Bye,

	Enrico


=========================================================
Enrico Sorcinelli - Gruppo E-Comm - Italia On Line S.p.a.
E-Mail: e.sorcinelli@pisa.iol.it - enrico@sorcinelli.it
=========================================================