sun.com docs.sun.com My Sun Worldwide Sites

Previous Previous     Contents     Index     Next Next

Sun::Solaris::Exacct::Object::Item Module

The Sun::Solaris::Exacct::Object::Item module is used for exacct data Items. An exacct data Item is represented as an opaque reference, blessed into the Sun::Solaris::Exacct::Object::Item class, which is a subclass of the Sun::Solaris::Exacct::Object class. The underlying exacct data types are mapped onto Perl types as follows.

Table 4-3 exacct Data Types Mapped to Perl Data Types

exacct type

Perl internal type

EXT_UINT8

IV (integer)

EXT_UINT16

IV (integer)

EXT_UINT32

IV (integer)

EXT_UINT64

IV (integer)

EXT_DOUBLE

NV (double)

EXT_STRING

PV (string)

EXT_EXACCT_OBJECT

Sun::Solaris::Exacct::Object subclass

EXT_RAW

PV (string)

Sun::Solaris::Exacct::Object::Item Constants

Sun::Solaris::Exacct::Object::Item has no constants.

Sun::Solaris::Exacct::Object::Item Functions, Class Methods, and Object Methods

Sun::Solaris::Exacct::Object::Item has no functions.

Sun::Solaris::Exacct::Object::Item inherits all class methods from the Sun::Solaris::Exacct::Object base class, plus the new() class method.

new

Sun::Solaris::Exacct::Object::Item inherits all object methods from the Sun::Solaris::Exacct::Object base class.

Sun::Solaris::Exacct::Object::Item Exports

Sun::Solaris::Exacct::Object::Item has no exports.

Sun::Solaris::Exacct::Object::Group Module

The Sun::Solaris::Exacct::Object::Group module is used for exacct Group objects. An exacct Group object is represented as an opaque reference, blessed into the Sun::Solaris::Exacct::Object::Group class, which is a subclass of the Sun::Solaris::Exacct::Object class. The Items within a Group are stored inside a Perl array, and a reference to the array can be accessed via the inherited value() method. This means that the individual Items within a Group can be manipulated with the normal Perl array syntax and operators. All data elements of the array must be derived from the Sun::Solaris::Exacct::Object class. Group objects can also be nested inside each other merely by adding an existing Group as a data Item.

Sun::Solaris::Exacct::Object::Group Constants

Sun::Solaris::Exacct::Object::Group has no constants.

Sun::Solaris::Exacct::Object::Group Functions, Class Methods, and Object Methods

Sun::Solaris::Exacct::Object::Group has no functions.

Sun::Solaris::Exacct::Object::Group inherits all class methods from the Sun::Solaris::Exacct::Object base class, plus the new() class method.

new

Sun::Solaris::Exacct::Object::Group inherits all object methods from the Sun::Solaris::Exacct::Object base class, plus the new() class method.

as_hash

as_hashlist

Sun::Solaris::Exacct::Object::Group Exports

Sun::Solaris::Exacct::Object::Group has no exports.

Sun::Solaris::Exacct::Object::_Array Module

The Sun::Solaris::Exacct::Object::_Array class is used internally for enforcing type checking of the data Items that are placed in an exacct Group. Sun::Solaris::Exacct::Object::_Array should not be created directly by the user.

Sun::Solaris::Exacct::Object::_Array Constants

Sun::Solaris::Exacct::Object::_Array has no constants.

Sun::Solaris::Exacct::Object::_Array Functions, Class Methods, and Object Methods

Sun::Solaris::Exacct::Object::_Array has no functions.

Sun::Solaris::Exacct::Object::_Array has internal-use class methods.

Sun::Solaris::Exacct::Object::_Array uses perl TIEARRAY methods.

Sun::Solaris::Exacct::Object::_Array Exports

Sun::Solaris::Exacct::Object::_Array has no exports.

Perl Code Examples

This section shows perl code examples for accessing exacct files.

Example 4-1 Using the Pseudocode Prototype

In typical use the Perl exacct library reads existing exacct files. Use pseudocode to show the relationships of the various Perl exacct classes. Illustrate in pseudocode the process of opening and scanning an exacct file, and processing objects of interest. In the following pseudocode, the 'convenience' functions are used in the interest of clarity.

-- Open the exacct file ($f is a Sun::Solaris::Exacct::File)
my $f = ea_new_file(...)

-- While not EOF ($o is a Sun::Solaris::Exacct::Object)
while (my $o = $f->get())

        -- Check to see if object is of interest
        if ($o->type() == &EO_ITEM)
             ...

        -- Retrieve the catalog ($c is a Sun::Solaris::Exacct::Catalog)
        $c = $o->catalog()

        -- Retrieve the value
        $v = $o->value();

        -- $v is a reference to a Sun::Solaris::Exacct::Group for a Group
        if (ref($v))
              ....

        -- $v is perl scalar for Items
        else

Example 4-2 Recursively dumping an exacct Object

sub dump_object
{
    my ($obj, $indent) = @_;
    my $istr = '  ' x $indent;

    #
    # Retrieve the catalog tag.  Because we are doing this in an array
    # context, the catalog tag will be returned as a (type, catalog, id) 
    # triplet, where each member of the triplet will behave as an integer
    # or a string, depending on context.  If instead this next line provided
    # a scalar context, e.g.
    #    my $cat  = $obj->catalog()->value();
    # then $cat would be set to the integer value of the catalog tag.
    #
    my @cat = $obj->catalog()->value();

    #
    # If the object is a plain item
    #
    if ($obj->type() == &EO_ITEM) {
          #
          # Note:  The '%s' formats provide s string context, so the
          # components of the catalog tag will be displayed as the
          # symbolic values.  If we changed the '%s' formats to '%d',
          # the numeric value of the components would be displayed.
          #
          printf("%sITEM\n%s  Catalog = %s|%s|%s\n", 
              $istr, $istr, @cat);
          $indent++;

          #
          # Retrieve the value of the item.  If the item contains in 
          # turn a nested exacct object (i.e. a item or group), then 
          # the value method will return a reference to the appropriate 
          # sort of perl object (Exacct::Object::Item or 
          # Exacct::Object::Group). We could of course figure out that 
          # the item contained a nested item or group by examining 
          # the catalog tag in @cat and looking for a type of 
          # EXT_EXACCT_OBJECT or EXT_GROUP.
          my $val = $obj->value();
          if (ref($val)) {
             # If it is a nested object, recurse to dump it.
             dump_object($val, $indent);
          } else {
             # Otherwise it is just a 'plain' value, so display it.
             printf("%s  Value = %s\n", $istr, $val);
          }

        #
        # Otherwise we know we are dealing with a group.  Groups represent
        # contents as a perl list or array (depending on context), so we 
        # can process the contents of the group with a 'foreach' loop, which
        # provides a list context.  In a list context the value method 
        # returns the content of the group as a perl list, which is the 
        # quickest mechanism, but doesn't allow the group to be modified. 
        # If we wanted to modify the contents of the group we could do so 
        # like this:
        #    my $grp = $obj->value();   # Returns an array reference
        #    $grp->[0] = $newitem;
        # but accessing the group elements this way is much slower.
        #
        } else {
                printf("%sGROUP\n%s  Catalog = %s|%s|%s\n",
                    $istr, $istr, @cat);
                $indent++;
                # 'foreach' provides a list context.
                foreach my $val ($obj->value()) {
                        dump_object($val, $indent);
                }
                printf("%sENDGROUP\n", $istr);
        }
}

Previous Previous     Contents     Index     Next Next
Company Info Contact Terms of Use Privacy Copyright 1994-2007 Sun Microsystems, Inc.