NAME
AFS::Object - Base class for encapsulating AFS::Command results
SYNOPSIS
This module is not used directly by applications, only indirectly through the return values of the various AFS::Command::* methods.
DESCRIPTION
This class is used by the various AFS::Command classes to encapsulate data returned from any command that has structured return values. In the simplest case, this object just encapsulates a simple list of key/value pairs. Each distinct key is represented as an object attribute, and is query-able via one of several methods documented below.
There are numerous subclasses of this class, which are used when objects must contains other objects, and these subclasses just implement special methods for querying the embedded objects.
METHODS
In all of the example code snippets below, $result is assumed to be an AFS::Object object, or an object derived from it.
listAttributes
This method takes no arguments, and returns a list of the attribute names available in the object.
my @attrs = $result->listAttributes();
foreach my $attr ( @attrs ) {
my $value = $result->getAttribute($attr);
print "Key '$attr' has value '$value\n";
}
getAttribute
This methods takes a single argument, the name of an attribute, and returns the value of the attribute, if it exists in the object.
my $name = $result->getAttribute('name');
NOTE: Attributes may also be queried by calling the method of the same name. If the attribute doesn't exist, then the method will just return a false value. The above example is the same as:
my $name = $result->name();
BEWARE: It is impossible to tell the difference between a non-existent attribute, and one with a false value using this method. If attribute existence is interesting to you (or to your code, I suppose), use the hasAttribute method.
getAttributes
This method takes no arguments, and returns the entire list of attributes as list of key/value pairs.
my %attrs = $result->getAttributes();
while ( my ($key,$value) = each %attrs ) {
print "Key '$key' has value '$value'\n";
}
hasAttribute
This method takes a single argument, the name of a potentially available attribute, and returns a boolean true/false value if the attribute exists in the object.
if ( $result->hasAttribute('name') ) {
# Well, then it has a name attribute...
}
SEE ALSO
AFS::Command(1), AFS::Command::Base(1)