Skip to content

Instantly share code, notes, and snippets.

@ziguzagu
Last active January 4, 2016 08:19
Show Gist options
  • Select an option

  • Save ziguzagu/8594775 to your computer and use it in GitHub Desktop.

Select an option

Save ziguzagu/8594775 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
package Foo {
sub new { bless {}, shift }
sub AUTOLOAD {
my $self = shift;
our $AUTOLOAD;
my ($meth) = $AUTOLOAD =~ m{::([^:]+)$};
{
warn "* Register $AUTOLOAD\n";
no strict 'refs';
*{$AUTOLOAD} = sub { print "$meth\n" };
}
goto &$AUTOLOAD;
}
sub DESTROY {}
};
package FooBar {
use base 'Foo';
sub bar { shift->SUPER::bar }
};
package main {
my $foo = FooBar->new;
$foo->bar;
$foo->bar;
};
1;
__END__
=pod
## perl 5.16.3
➜ perl autoload-super.pl
* Register FooBar::SUPER::bar
bar
bar
## perl 5.18.2
➜ perl autoload-super.pl
* Register FooBar::SUPER::bar
bar
* Register FooBar::SUPER::bar
Subroutine FooBar::SUPER::bar redefined at autoload-super.pl line 17.
bar
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment