22 return $_[0]->{'oidptr'}->to_string();
26 return $_[0]->{'oidptr'}->length();
33 if (ref($str) eq 'NetSNMP::OID') {
34 return $this->{'oidptr'}->append_oid($str->{'oidptr'});
36 $str = "." . $str if ($str =~ /^\d+/);
37 if ($str =~ /^[.\d]+/) {
39 return $this->{'oidptr'}->append($str);
41 if ($str =~ /^\"(.*)\"$/) {
43 my $newstr = "." . CORE::length($1);
44 map { $newstr .= ".$_" } unpack("c*",$1);
45 return $this->{'oidptr'}->append($newstr);
47 if ($str =~ /^\'(.*)\'$/) {
48 # string index, implied
50 map { $newstr .= ".$_" } unpack("c*",$1);
51 return $this->{'oidptr'}->append($newstr);
54 return $this->{'oidptr'}->append($str);
60 my ($newoid, %newhash);
62 $newoid->{'oidptr'} = $this->{'oidptr'}->clone();
63 bless($newoid, ref($this));
64 $newoid->append($str);
68 use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $AUTOLOAD);
70 @ISA = qw(Exporter DynaLoader);
72 # Items to export into callers namespace by default. Note: do not export
73 # names by default without a very good reason. Use EXPORT_OK instead.
74 # Do not simply export all your public functions/methods/constants.
76 # This allows declaration use NetSNMP::OID ':all';
77 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
79 %EXPORT_TAGS = ( 'all' => [ qw(
84 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
97 $type = "NetSNMP::OID";
99 SNMP::init_snmp("perl");
100 my $ptr = NetSNMP::OID::newptr($arg);
102 return newwithptr($type, $ptr);
112 $type = "NetSNMP::OID";
114 SNMP::init_snmp("perl");
115 $self->{'oidptr'} = $ptr;
120 sub snmp_oid_compare($$) {
121 my ($oid1, $oid2) = @_;
122 return _snmp_oid_compare($oid1->{oidptr}, $oid2->{oidptr});
127 snmp_oid_compare($v1, $v2);
132 $v1->{'oidptr'}->to_string cmp $v2->{'oidptr'}->to_string;
137 return $self->{oidptr}->to_array();
141 # This AUTOLOAD is used to 'autoload' constants from the constant()
142 # XS function. If a constant is not found then control is passed
143 # to the AUTOLOAD in AutoLoader.
146 ($constname = $AUTOLOAD) =~ s/.*:://;
147 croak "& not defined" if $constname eq 'constant';
148 my $val = constant($constname, @_ ? $_[0] : 0);
150 if ($! =~ /Invalid/ || $!{EINVAL}) {
151 $AutoLoader::AUTOLOAD = $AUTOLOAD;
152 goto &AutoLoader::AUTOLOAD;
155 croak "Your vendor has not defined NetSNMP::OID macro $constname";
160 # Fixed between 5.005_53 and 5.005_61
162 *$AUTOLOAD = sub () { $val };
165 *$AUTOLOAD = sub { $val };
171 bootstrap NetSNMP::OID $VERSION;
173 # Preloaded methods go here.
175 # Autoload methods go after =cut, and are processed by the autosplit program.
179 # Below is stub documentation for your module. You better edit it!
183 NetSNMP::OID - Perl extension for manipulating OIDs
189 my $oid = new NetSNMP::OID('sysContact.0');
191 if ($oid < new NetSNMP::OID('ifTable')) {
195 my @numarray = $oid->to_array();
198 $oid = new NetSNMP::OID('.1.3');
202 # appending index strings
204 $oid2 = $oid + "\"wes\"";
205 # -> .1.3.6.1.3.119.101.115
207 $oid3 = $oid + "\'wes\'";
208 # -> .1.3.6.1.119.101.115
210 $len = $oid3->length();
215 The NetSNMP::OID module is a simple wrapper around a C-based net-snmp
216 oid (which is an array of unsigned integers). The OID is internally
217 stored as a C array of integers for speed purposes when doing
220 The standard logical expression operators (<, >, ==, ...) are
221 overloaded such that lexographical comparisons may be done with them.
223 The + operator is overloaded to allow you to append stuff on to the
224 end of a OID, like index segments of a table, for example.
228 int snmp_oid_compare(oid1, oid2)
229 int compare(oid1, oid2)
233 Wes Hardaker, E<lt>hardaker@users.sourceforge.netE<gt>
241 Copyright (c) 2002 Networks Associates Technology, Inc. All
242 Rights Reserved. This program is free software; you can
243 redistribute it and/or modify it under the same terms as Perl