Fix AUTOLOAD / can() bug that could result in DESTROY being redefined and dynamic methods not being added to the symbol table.
This commit is contained in:
@@ -4690,21 +4690,27 @@ sub can {
|
|||||||
my $funcs = $self->funcs();
|
my $funcs = $self->funcs();
|
||||||
|
|
||||||
# We need to resolve funcs with a prefix or suffix
|
# We need to resolve funcs with a prefix or suffix
|
||||||
my $f_method = $method;
|
my $base_method = $method;
|
||||||
$f_method =~ s/^(load|orig)_//;
|
$base_method =~ s/^(load|orig)_//;
|
||||||
$f_method =~ s/_raw$//;
|
$base_method =~ s/_raw$//;
|
||||||
|
|
||||||
no strict 'refs'; ## no critic (ProhibitNoStrict )
|
no strict 'refs'; ## no critic (ProhibitNoStrict )
|
||||||
|
|
||||||
|
# We could add load_/orig_/_raw alternatives to symbol table here on
|
||||||
|
# first call of any type for a global or func since they all use the same
|
||||||
|
# destination code, but they aren't used heavily in main code base so
|
||||||
|
# we’ll just create if/when they are called rather than pollute the
|
||||||
|
# symbol table with entries that never get called.
|
||||||
|
|
||||||
# Check for set_ ing.
|
# Check for set_ ing.
|
||||||
if ( $method =~ /^set_/ ) {
|
if ( $method =~ /^set_/ ) {
|
||||||
return *{$AUTOLOAD} = _make_setter( $method, $oid, @_ );
|
return *{$method} = _make_setter( $method, $oid, @_ );
|
||||||
}
|
}
|
||||||
elsif ( defined $funcs->{$f_method} || $table ) {
|
elsif ( defined $funcs->{$base_method} || $table ) {
|
||||||
return *{$AUTOLOAD} = _load_attr( $method, $oid, @_ );
|
return *{$method} = _load_attr( $method, $oid, @_ );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return *{$AUTOLOAD} = _global( $method, $oid );
|
return *{$method} = _global( $method, $oid );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4744,12 +4750,12 @@ subclass.
|
|||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
our $AUTOLOAD;
|
||||||
|
|
||||||
sub AUTOLOAD {
|
sub AUTOLOAD {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($sub_name) = $AUTOLOAD =~ /::(\w+)$/;
|
my ($sub_name) = $AUTOLOAD =~ /::(\w+)$/;
|
||||||
|
|
||||||
return if $sub_name =~ /DESTROY$/;
|
|
||||||
|
|
||||||
# Typos in function calls in SNMP::Info subclasses turn into
|
# Typos in function calls in SNMP::Info subclasses turn into
|
||||||
# AUTOLOAD requests for non-methods. While this is deprecated,
|
# AUTOLOAD requests for non-methods. While this is deprecated,
|
||||||
# we'll still get called, so report a less confusing error.
|
# we'll still get called, so report a less confusing error.
|
||||||
@@ -4776,6 +4782,9 @@ sub AUTOLOAD {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Skip AUTOLOAD()
|
||||||
|
sub DESTROY {}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
=head1 COPYRIGHT AND LICENSE
|
=head1 COPYRIGHT AND LICENSE
|
||||||
|
|||||||
Reference in New Issue
Block a user