motemen (owner)

Revisions

gist: 199447 Download_button fork
public
Public Clone URL: git://gist.github.com/199447.git
Embed All Files: show embed
final.pl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use strict;
use warnings;
 
package A;
 
INIT {
    foreach (keys %::) {
        my ($module) = /^(.+)::$/ or next;
        eval { $module->isa(__PACKAGE__) } or next;
        no strict 'refs';
        no warnings 'redefine';
        ${"$module\::"}{foo} = \&foo;
    }
}
 
sub foo { 'A' }
sub bar { 'A' }
 
package B;
use base 'A';
 
sub foo { 'B' }
sub bar { 'B' }
 
package main;
 
warn B->foo; # A
warn B->bar; # B
 
1;