Perl: oo with use parent - checking if class has a parent -


i have perl objects built time ago not moose, bless, inheritance implemented using 'parent' pragma.

now know whether there way check whether class has used 'parent' or not.

e.g. if have 2 classes

package animal; sub new {     $class = shift;    return bless {}, $class; } 1; 

and

package cat; use parent 'animal';  sub new {     $class = shift;    return bless {}, $class; } 1; 

would there check make determine 'cat' class has parent ( not care which, not ), , animal not, given $foo either of them?

i can't picture why you'd ever want know this, it's possible using following:

use mro; $inherits = @{ mro::get_linear_isa($class) } > 1; 

or

my $isa = { no strict 'refs'; \@{ $class . '::isa' } }; $inherits = @$isa; 

notes:

  1. all classes inherit universal, that's ignored unless class explicitly declares inherits it.
  2. these methods don't care how inheritance declared (use parent or other means).

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -