perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Förtsch <torsten.foert...@gmx.net>
Subject Re: Is it me or is mod_perl extremely dangerous?
Date Wed, 07 Dec 2011 13:05:19 GMT
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


Mime
View raw message