From 91b98085f61e0498069f0ff56b8239d4a3f1cbdc Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Wed, 21 Mar 2018 23:41:16 -0400 Subject: [PATCH] Fix AUTOLOAD / can() bug that could result in DESTROY being redefined and dynamic methods not being added to the symbol table. --- lib/SNMP/Info.pm | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/SNMP/Info.pm b/lib/SNMP/Info.pm index dcb33599..29226fd1 100644 --- a/lib/SNMP/Info.pm +++ b/lib/SNMP/Info.pm @@ -4690,21 +4690,27 @@ sub can { my $funcs = $self->funcs(); # We need to resolve funcs with a prefix or suffix - my $f_method = $method; - $f_method =~ s/^(load|orig)_//; - $f_method =~ s/_raw$//; + my $base_method = $method; + $base_method =~ s/^(load|orig)_//; + $base_method =~ s/_raw$//; 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. if ( $method =~ /^set_/ ) { - return *{$AUTOLOAD} = _make_setter( $method, $oid, @_ ); + return *{$method} = _make_setter( $method, $oid, @_ ); } - elsif ( defined $funcs->{$f_method} || $table ) { - return *{$AUTOLOAD} = _load_attr( $method, $oid, @_ ); + elsif ( defined $funcs->{$base_method} || $table ) { + return *{$method} = _load_attr( $method, $oid, @_ ); } else { - return *{$AUTOLOAD} = _global( $method, $oid ); + return *{$method} = _global( $method, $oid ); } } @@ -4744,12 +4750,12 @@ subclass. =cut +our $AUTOLOAD; + sub AUTOLOAD { my $self = shift; my ($sub_name) = $AUTOLOAD =~ /::(\w+)$/; - return if $sub_name =~ /DESTROY$/; - # Typos in function calls in SNMP::Info subclasses turn into # AUTOLOAD requests for non-methods. While this is deprecated, # we'll still get called, so report a less confusing error. @@ -4776,6 +4782,9 @@ sub AUTOLOAD { } +# Skip AUTOLOAD() +sub DESTROY {} + 1; =head1 COPYRIGHT AND LICENSE