in reply to purpose of Super keyword
#!/usr/bin/perl use Data::Dumper; use Animal::Dog; my $rex = Animal::Dog->new(); print Dumper($rex);
package Animal; use strict; use warnings; sub new { my ($class) = @_; my $proto = {need_oxygen => 1}; return bless($proto, $class); } 1;
package Animal::Dog; use base "Animal"; use strict; use warnings; sub new { my ($class) = @_; my $self = $class->SUPER::new(); $$self{domesticated} = 1; return $self; } 1;
$VAR1 = bless( { 'domesticated' => 1, 'need_oxygen' => 1 }, 'Animal::Dog' );
For instance, in Animal::Dog::Husky->some_method body, you can call some inherited method and you do not care if that method is written in Animal or in Animal::Dog class.
UPDATE: s/inherited/overiden/
|
|---|