PerlOnTheWay has asked for the wisdom of the Perl Monks concerning the following question:
[test@test ~]$ perl -we ' package grand_father; use base qw/Class::Accessor::Fast/; sub new { my $class=shift; return $class->SUPER::new(@_); } package father; use base grand_father; sub new { my $self=shift->SUPER::new(@_); return $self; } package son; use base father; package main; use Data::Dumper; print Dumper(son->new);
output:
$VAR1 = bless( {}, 'son' );It seems to me the line my $self=shift->SUPER::new(@_); should cause dead loop,but it actually works fine.
My reasoning:
As SUPER should look up new in its parent ,so dead loop will occur.
Anyone can explain how SUPER works ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why doesn't SUPER cause dead loop here?
by ikegami (Patriarch) on Sep 02, 2011 at 02:46 UTC | |
by PerlOnTheWay (Monk) on Sep 02, 2011 at 02:51 UTC | |
by ikegami (Patriarch) on Sep 02, 2011 at 02:52 UTC | |
by PerlOnTheWay (Monk) on Sep 02, 2011 at 03:06 UTC | |
by Anonymous Monk on Sep 02, 2011 at 04:28 UTC | |
by ikegami (Patriarch) on Sep 02, 2011 at 05:01 UTC | |
by Anonymous Monk on Sep 02, 2011 at 06:56 UTC | |
by ikegami (Patriarch) on Sep 02, 2011 at 08:22 UTC | |
|