From 827398228c267a5c8b2d42e868e9d51c9da692f5 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 18 Jun 2014 13:20:26 +0100 Subject: [PATCH] Add superclass discovery methods --- ChangeLog | 6 ++++++ Info.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/ChangeLog b/ChangeLog index ed3668e5..c47cee77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ SNMP::Info - Friendly OO-style interface to Network devices using SNMP. +version 3.16 + + [ENHANCEMENTS] + + * Add superclass discovery methods (super_path and print_super_path) + version 3.15 (2014-07-10) [NEW FEATURES] diff --git a/Info.pm b/Info.pm index 601ac8bc..94bc811b 100644 --- a/Info.pm +++ b/Info.pm @@ -1223,6 +1223,56 @@ sub new { return $auto_specific ? $new_obj->specify() : $new_obj; } +=item super_path() + +Returns the list (in order) of the names of classes Perl will search to find +methods for this SNMP::Info class or object instance. + +Can be called as either a class or object method: + + # class method: + my @list = SNMP::Info::Layer3::Juniper->super_path(); + # object method: + my @list = $info->super_path(); + +Note this B the L distribution to be installed. + +=cut + +sub super_path { + my $self = shift; + my $class = (ref $self ? ref $self : $self); + + # Load Class::ISA, if we can + eval { require Class::ISA }; ## no critic + if ($@) { + croak "SNMP::Info::super_path() Failed to load Class::ISA (is it installed?). $@\n"; + } + else { + return Class::ISA::self_and_super_path( $class ); + } +} + +=item print_super_path() + +Prints the list (in order) of the names of classes Perl will search to find +methods for this SNMP::Info class or object instance. + +Can be called as either a class or object method: + + # class method: + SNMP::Info::Layer3::Juniper->print_super_path(); + # object method: + $info->print_super_path(); + +Note this B the L distribution to be installed. + +=cut + +sub print_super_path { + print join ("\n", (shift)->super_path), "\n"; +} + =item update() Replace the existing session with a new one with updated values,