Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In perl, is $self->subname the same as $self->MYPACKAGE::subname?

In perl, is $self->subname the same as $self->MYPACKAGE::subname? It’s me the author of Pythonizer with yet another piece of mystery Perl code, this one is again from CGI.pm. Here the code is taking $self, which is an instance variable of the CGI package, and then calling the hidden function, defined within, but the code doesn’t just use $self->hidden(...), it uses $self->CGI::hidden(...). When I translate this to Python as self.CGI.hidden(...), I get an error that the CGI class doesn’t have a CGI attribute. I’m wondering if I should make a CGI attribute in this case that just points back to the class instance (or should it point to the class)? Anyhow, what exactly does this mean? Thanks!

package CGI;
...
sub hidden { ... }
...
$self->CGI::hidden(...);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In perl, is $self->subname the same as $self->MYPACKAGE::subname

No.

$self->subname will look up subname´ in the symbol table associated with object $self, which is the symbol table from the package were $self` is blessed into.

$self->MYPACKAGE::subname instead is basically calling MYPACKAGE::subname($self), i.e. it will not lookup the method in the symbol table associated with $self but instead in the symbol table for MYPACKAGE. $self might not even have a method `subname´.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading