poodad has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to simplify a terribly complicated network inventory program by using objects, but I can't figure out how to do what I want to do.
Given a list of pingable IP addresses, I use async SNMP to query sysName, sysDesc, and sysObjectID. This part is easy.
But here's where I get stuck. Given the IP addresses that reply to the SNMP query, I want to create an SNMPDevice object. However, in the constructor of SMNPDevice, I want to do some additional queries to see if the device requires special handling (like a cisco switch stack where one IP address actually consists of multiple hardware units). If a special device type is detected, I want the SNMPDevice object to create an object of the appropriate derived class (like SNMPDevice::CiscoStack) and returning it instead of its own blessed self.Something like this:
Or, would SNMPDevice bless itself as a SNMPDevice::CiscoStack ?package SMNPDevice; sub new { my $class = shift; my $ip = shift; my $sysName = shift; my $sysDesc = shift; my $sysObjectID = shift; my @members = GetStackMembers($ip); return SNMPObject::CiscoStack::new($ip, $sysName, $sysDesc, $sysObj +ectID) if scalar @members > 1; return SNMPDevice::CiscoWLC::new($ip, $sysName, $sysDesc, $sysObjec +tID) if $sysDesc =~ /Cisco WLC/; #etc }
|
|---|