![]() |
|
P is for Practical | |
PerlMonks |
Re^4: Thoughts on new 'class' OO in upcoming perlby haj (Vicar) |
on Mar 08, 2023 at 19:04 UTC ( [id://11150860]=note: print w/replies, xml ) | Need Help?? |
What you wrote about parent presumably also applies to base and any code that manipulates @ISA (either directly or via a module). Correct! In core Perl OO, @ISA is set to readonly as soon as the class declaration has been processed. I think it makes sense to maintain the value for reading. About your code example: That construct is currently a syntax error. Once a class has been "closed" by ending the enclosing block, file, or like in your example by opening another namespace with package Y;, that namespace is "sealed": Cannot reopen existing class "X" Everything else would be at least messy (consider e.g. conflicting parent classes or version declarations). And while this is a restriction compared to the sloppy package rules, I can not imagine a problem which can be adequately solved by re-opening a class. There is a bit of a grey zone. Code like this is "valid":
So, as of today, you can re-open an existing namespace as a package, as always before. Subroutines can be written like old-style "methods" in that package. They are resolved as expected You can even override a method. The method gets the core OO object as its first parameter. But in those creepy methods you do not have access to the fields of the class with the same (nor can you write them as method, to begin with). Having code implanted into the namespace does not give special access to the object. Perl 5 is not known for being eager to prohibit creepy code, so I guess it will stay that way.
In Section
Meditations
|
|