> (untested, till someone provides a real SSCCE)
here we go to prove my theory
this works (in a wider sense ;):
use strict;
use warnings;
# https://perlmonks.org/?node_id=11137026
package Base;
use Data::Dumper;
sub AUTOLOAD {
our $AUTOLOAD;
warn "$AUTOLOAD => ", Dumper \@_;
}
#*UNIVERSAL::AUTOLOAD = \&AUTOLOAD;
package Bla;
*AUTOLOAD = \&Base::AUTOLOAD; # aka Bla::AUTOLOAD
some_sub(1,2,3);
*Foo::AUTOLOAD = \&Base::AUTOLOAD;
Foo::some_sub(4,5,6)
-*- mode: compilation; default-directory: "d:/tmp/pm/" -*-
Compilation started at Wed Sep 29 12:33:29
C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/universal_autoload.pl
Name "Foo::AUTOLOAD" used only once: possible typo at d:/tmp/pm/univer
+sal_autoload.pl line 25.
Name "Bla::AUTOLOAD" used only once: possible typo at d:/tmp/pm/univer
+sal_autoload.pl line 19.
Bla::some_sub => $VAR1 = [
1,
2,
3
];
Foo::some_sub => $VAR1 = [
4,
5,
6
];
Compilation finished at Wed Sep 29 12:33:29
this horribly fails (please note also all those potential problems caused by UNIVERSAL::AUTOLOAD by triggering with intentionally undefined methods)
use strict;
use warnings;
# https://perlmonks.org/?node_id=11137026
package Base;
use Data::Dumper;
sub AUTOLOAD {
our $AUTOLOAD;
return if $AUTOLOAD =~ /::DESTROY$/; # ignore destruction *
warn "$AUTOLOAD => ", Dumper \@_;
}
*UNIVERSAL::AUTOLOAD = \&AUTOLOAD;
package Bla;
*AUTOLOAD = \&Base::AUTOLOAD; # aka Bla::AUTOLOAD
some_sub(1,2,3);
#*Foo::AUTOLOAD = \&Base::AUTOLOAD;
Foo::some_sub(4,5,6)
-*- mode: compilation; default-directory: "d:/tmp/pm/" -*-
Compilation started at Wed Sep 29 12:37:45
C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/universal_autoload.pl
Name "UNIVERSAL::AUTOLOAD" used only once: possible typo at d:/tmp/pm/
+universal_autoload.pl line 15.
Name "Bla::AUTOLOAD" used only once: possible typo at d:/tmp/pm/univer
+sal_autoload.pl line 20.
Bla::some_sub => $VAR1 = [
1,
2,
3
];
Use of inherited AUTOLOAD for non-method Foo::some_sub() is no longer
+allowed at d:/tmp/pm/universal_autoload.pl line 28.
Compilation exited abnormally with code 255 at Wed Sep 29 12:37:45
update
*) added, otherwise the output is littered with all objects with undefined DESTROY methods triggering AUTOLOAD.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.