Last active
January 4, 2016 08:19
-
-
Save ziguzagu/8594775 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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