#!/usr/bin/perl use strict; use warnings; package Bar; our @ISA = qw(Foo); sub data { my $self = shift; return $self->SUPER::data(@_); } package Foo; our $AUTOLOAD; sub AUTOLOAD { my $self = shift; return if $AUTOLOAD =~ /^(.*::)?DESTROY$/; no strict 'refs'; my $old = defined *{$AUTOLOAD} ? *{$AUTOLOAD}{CODE}//'' : ''; my $force_new_code_ref = ''; *{$AUTOLOAD} = sub { warn "running sub $force_new_code_ref"; }; # usually a getter/setter, but simplified here. my $new = *{$AUTOLOAD}{CODE}; warn "installed sub AUTOLOAD=$AUTOLOAD new=$new old=$old"; &$new($self, @_); } package main; my $bar = bless {}, 'Bar'; $bar->data('baz'); $bar->data('bip'); $bar->data('bop'); $bar->data('boo'); #### $ perlbrew switch 5.14.4 $ perl ./doit.pl installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x25e5d48) old= at ./doit.pl line 29. running sub at ./doit.pl line 25. running sub at ./doit.pl line 25. running sub at ./doit.pl line 25. running sub at ./doit.pl line 25. $ perlbrew switch 5.16.3 $ perl ./doit.pl # v5.16.3 installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1f32970) old= at ./doit.pl line 29. running sub at ./doit.pl line 25. running sub at ./doit.pl line 25. running sub at ./doit.pl line 25. running sub at ./doit.pl line 25. $ perlbrew switch 5.18.4 $ perl ./doit.pl installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x16138e8) old= at ./doit.pl line 29. running sub at ./doit.pl line 25. Subroutine Bar::SUPER::data redefined at ./doit.pl line 25. installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1613858) old=CODE(0x16138e8) at ./doit.pl line 29. running sub at ./doit.pl line 25. Subroutine Bar::SUPER::data redefined at ./doit.pl line 25. installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1613768) old=CODE(0x1613858) at ./doit.pl line 29. running sub at ./doit.pl line 25. Subroutine Bar::SUPER::data redefined at ./doit.pl line 25. installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1613888) old=CODE(0x1613768) at ./doit.pl line 29. running sub at ./doit.pl line 25. $ perlbrew switch perl-blead $ perl -v | grep built This is perl 5, version 25, subversion 5 (v5.25.5 (v5.25.4-61-g483efd0)) built for x86_64-linux $ perl ./doit.pl installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1aeedc8) old= at ./doit.pl line 29. running sub at ./doit.pl line 25. Subroutine Bar::SUPER::data redefined at ./doit.pl line 25. installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1aeed38) old=CODE(0x1aeedc8) at ./doit.pl line 29. running sub at ./doit.pl line 25. Subroutine Bar::SUPER::data redefined at ./doit.pl line 25. installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1aeec48) old=CODE(0x1aeed38) at ./doit.pl line 29. running sub at ./doit.pl line 25. Subroutine Bar::SUPER::data redefined at ./doit.pl line 25. installed sub AUTOLOAD=Bar::SUPER::data new=CODE(0x1aeed68) old=CODE(0x1aeec48) at ./doit.pl line 29. running sub at ./doit.pl line 25.