Perl final, . :
BEGIN {
package final;
$INC{'final.pm'}++;
use Variable::Magic qw(wizard cast);
sub import {
my (undef, $symbol) = @_;
my ($stash, $name) = $symbol =~ /(.+::)(.+)/;
unless ($stash) {
$stash = caller().'::';
$name = $symbol;
$symbol = $stash.$name;
}
no strict 'refs';
my $glob = \*$symbol;
my $code = \&$glob;
my ($seen, @last);
cast %$stash, wizard store => sub {
if ($_[2] eq $name and $code != \&$glob) {
print "final subroutine $symbol was redefined ".
"at $last[1] line $last[2].\n" unless $seen++
}
@last = caller
}
}
}
:
use warnings;
use strict;
{
package Foo;
sub hello {print "HI"}
use final 'hello';
}
package main;
no warnings;
sub Foo::hello {print "bye"}
Foo::hello();
- :
final subroutine Foo::hello was redefined at filename.pl line 9.
bye
, , (- perl Variable::Magic). , .
no warnings; , perl . , , use warnings . :
Perl . , , , .