Re: Is it me or is mod_perl extremely dangerous?

Torsten Förtsch <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
On Wednesday, 07 December 2011 13:32:01 Tuomo Salo wrote:
> Please do not do that.
> 
> When you use a "my" variable outside a subroutine, you create a variable
> that is completely invisible from anywhere outside of that file.

Just my 2¢: Of course it is completely valid to use a my variable outside a 
function. Just keep in mind that it keeps its state across invocations.

As for your example, why don't you reimplement output() in your subclass?

If I understand you correctly, you'd rather:

--------------
package MyClass;

our $class_level_attribute = "I Am MyClass";
...
--------------

and later:

-------------
package SubClass;

use base MyClass;

$MyClass::class_level_attribute = "I want to be SubClass";
-------------


Now suppose for a moment another subclass:

-------------
package SubClass2;

use base MyClass;

$MyClass::class_level_attribute = "I want to be SubClass2";
-------------


What do you expect MyClass->new->output to print?


You can prevent confusion by:

-------------
package SubClass;

use base MyClass;

sub output {
  local $MyClass::class_level_attribute = "I want to be SubClass";
  shift->SUPER::output(@_);
}
-------------

Now you really rely on an implementation detail of MyClass. Let's hope this 
usage of $MyClass::class_level_attribute is documented.

Torsten Förtsch

-- 
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.