SNMP::Class::ResultSet
SNMP::Class::ResultSet - A list of SNMP::Class::Varbind objects.
VERSION
Version 0.12
SYNOPSIS
use SNMP::Class::ResultSet;
my $foo = SNMP::Class::ResultSet->new;
$foo->push($vb1);
...
#later:
...
METHODS
IMPORTANT NOTICE: All the methods that are returning a ResultSet will only do so when called in scalar context. They alternatively return the list of varbinds in list context.
new
Constructor. Just issue it without arguments. Creates an empty ResultSet. SNMP::Class::Varbind objects can later be stored in there using the push method.
smart_return
In scalar context, this method returns the object itself, while in list context returns the list of the varbinds. In null context, it will croak. This method is mainly used for internal purposes.
varbinds
Returns a reference to a list containing all the stored varbinds. Modifying the list alters the object.
dump
Returns a string representation of the entire ResultSet. Mainly used for debugging purposes.
push
Takes one argument, which must be an SNMP::Class::Varbind or a descendant of that class. Inserts it into the ResultSet.
pop
Pops a varbind out of the Set. Takes no arguments.
filter
filter can be used when there is the need to filter the varbinds inside the resultset using arbitrary rules. Takes one argument, which is a reference to a subroutine which will be doing the filtering. The subroutine must return an appropriate true or false value just like in CORE::grep. The value of each SNMP::Class::Varbind item in the ResultSet gets assigned to the $_ global variable. For example:
print $rs->filter(sub {$_->get_label_oid == 'sysName'});
If used in a scalar context, a reference to a new ResultSet containing the filter results will be returned. If used in a list context, a simple array containing the varbinds of the result will be returned. Please do note that in the previous example, the print function always forces list context, so we get what we want.
find
Filters based on key-value pairs that are labels and values. For example:
$rs->find('ifDescr' => 'eth0', ifDescr => 'eth1');
will find which are the instance oids of the row that has ifDescr equal to 'eth0' or 'eth1' (if any), and filter using that instances.
This means that to get the ifSpeed of eth0, one can simply issue:
my $speed = $rs->find('ifDescr' => 'eth0')->ifSpeed->value;
number_of_items
Returns the number of items present inside the ResultSet
is_empty
Reveals whether the ResultSet is empty or not.
dot
The dot method overloads the '.' operator, returns SNMP::Class::Varbind. Use it to get a single SNMP::Class::Varbind out of a ResultSet as a final instance filter. For example, if $rs contains ifSpeed.1, ifSpeed.2 and ifSpeed.3, then this call:
$rs.3
returns the ifSpeed.3 SNMP::Class::Varbind.
Please note that this method does not return a ResultSet like the instance method, but a Varbind which should be the sole member of the ResultSet having that instance. If the ResultSet has more than one Varbinds with the requested instance and the dot operator is used, a warning will be issued, and only the first matching Varbind will be returned
item
Returns the item of the ResultSet with index same as the first argument. No argument yields the first item (index 0) in the ResultSet.
AUTHOR
Athanasios Douitsis, <aduitsis at cpan.org>
BUGS
Please report any bugs or feature requests to bug-snmp-class-resultset at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SNMP::Class. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc SNMP::Class
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2007 Athanasios Douitsis, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.