xref: /onnv-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Exacct/Object/Object.pm (revision 12388:1bc8d55b0dfd)
10Sstevel@tonic-gate#
2*12388SJohn.Sonnenschein@Sun.COM# Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
30Sstevel@tonic-gate#
47298SMark.J.Nelson@Sun.COM
50Sstevel@tonic-gate#
60Sstevel@tonic-gate# Object.pm contains perl code for exacct object manipulation.
70Sstevel@tonic-gate#
80Sstevel@tonic-gate
98287SJohn.Sonnenschein@Sun.COMrequire 5.8.4;
100Sstevel@tonic-gateuse strict;
110Sstevel@tonic-gateuse warnings;
120Sstevel@tonic-gate
130Sstevel@tonic-gatepackage Sun::Solaris::Exacct::Object;
140Sstevel@tonic-gate
157298SMark.J.Nelson@Sun.COMour $VERSION = '1.3';
160Sstevel@tonic-gateuse XSLoader;
170Sstevel@tonic-gateXSLoader::load(__PACKAGE__, $VERSION);
180Sstevel@tonic-gate
190Sstevel@tonic-gateour (@EXPORT_OK, %EXPORT_TAGS, @_Constants);
200Sstevel@tonic-gate@EXPORT_OK = @_Constants;
210Sstevel@tonic-gate%EXPORT_TAGS = (CONSTANTS => \@_Constants, ALL => \@EXPORT_OK);
220Sstevel@tonic-gate
230Sstevel@tonic-gateuse base qw(Exporter);
240Sstevel@tonic-gateuse Sun::Solaris::Exacct::Catalog qw(:CONSTANTS);
250Sstevel@tonic-gate
260Sstevel@tonic-gate#
270Sstevel@tonic-gate# Class methods
280Sstevel@tonic-gate#
290Sstevel@tonic-gate
300Sstevel@tonic-gate#
310Sstevel@tonic-gate# Dump an exacct object to the specified filehandle, or STDOUT by default.
320Sstevel@tonic-gate#
330Sstevel@tonic-gatesub dump
340Sstevel@tonic-gate{
350Sstevel@tonic-gate	# Fettle parameters.
360Sstevel@tonic-gate	my ($class, $obj, $fh, $indent) = @_;
370Sstevel@tonic-gate	$fh ||= \*STDOUT;
380Sstevel@tonic-gate	$indent ||= 0;
390Sstevel@tonic-gate	my $istr = '  ' x $indent;
400Sstevel@tonic-gate
410Sstevel@tonic-gate	# Check for undef values.
420Sstevel@tonic-gate	if (! defined($obj)) {
430Sstevel@tonic-gate		print $fh ($istr, "UNDEFINED_VALUE\n");
440Sstevel@tonic-gate		return;
450Sstevel@tonic-gate	}
460Sstevel@tonic-gate
470Sstevel@tonic-gate	# Deal with items.
480Sstevel@tonic-gate	my @cat = $obj->catalog()->value();
490Sstevel@tonic-gate	if ($obj->type() == &EO_ITEM) {
500Sstevel@tonic-gate		printf $fh ("%sITEM\n%s  Catalog = %s|%s|%s\n",
510Sstevel@tonic-gate		   $istr, $istr, @cat);
520Sstevel@tonic-gate		$indent++;
530Sstevel@tonic-gate		my $val = $obj->value();
540Sstevel@tonic-gate
550Sstevel@tonic-gate		# Recursively dump nested objects.
560Sstevel@tonic-gate		if (ref($val)) {
570Sstevel@tonic-gate			$class->dump($val, $fh, $indent);
580Sstevel@tonic-gate
590Sstevel@tonic-gate		# Just print out items.
600Sstevel@tonic-gate		} else {
610Sstevel@tonic-gate			$val = unpack('H*', $val) if ($cat[0] == &EXT_RAW);
620Sstevel@tonic-gate			printf $fh ("%s  Value = %s\n", $istr, $val);
630Sstevel@tonic-gate		}
640Sstevel@tonic-gate
650Sstevel@tonic-gate	# Deal with groups.
660Sstevel@tonic-gate	} else {
670Sstevel@tonic-gate		printf $fh ("%sGROUP\n%s  Catalog = %s|%s|%s\n",
680Sstevel@tonic-gate		    $istr, $istr, @cat);
690Sstevel@tonic-gate		$indent++;
700Sstevel@tonic-gate		foreach my $val ($obj->value()) {
710Sstevel@tonic-gate			$class->dump($val, $fh, $indent);
720Sstevel@tonic-gate		}
730Sstevel@tonic-gate		printf $fh ("%sENDGROUP\n", $istr);
740Sstevel@tonic-gate	}
750Sstevel@tonic-gate}
760Sstevel@tonic-gate
770Sstevel@tonic-gate#
780Sstevel@tonic-gate# Item subclass - establish inheritance.
790Sstevel@tonic-gate#
800Sstevel@tonic-gatepackage Sun::Solaris::Exacct::Object::Item;
810Sstevel@tonic-gateuse base qw(Sun::Solaris::Exacct::Object);
820Sstevel@tonic-gate
830Sstevel@tonic-gate#
840Sstevel@tonic-gate# Group subclass - establish inheritance.
850Sstevel@tonic-gate#
860Sstevel@tonic-gatepackage Sun::Solaris::Exacct::Object::Group;
870Sstevel@tonic-gateuse base qw(Sun::Solaris::Exacct::Object);
880Sstevel@tonic-gate
890Sstevel@tonic-gate#
900Sstevel@tonic-gate# Tied array used for holding a group's items.
910Sstevel@tonic-gate#
920Sstevel@tonic-gatepackage Sun::Solaris::Exacct::Object::_Array;
930Sstevel@tonic-gateuse Carp;
940Sstevel@tonic-gate
950Sstevel@tonic-gate#
960Sstevel@tonic-gate# Check the passed list of arguments are derived from ::Object
970Sstevel@tonic-gate#
980Sstevel@tonic-gatesub check_args
990Sstevel@tonic-gate{
1000Sstevel@tonic-gate	my @duff;
1010Sstevel@tonic-gate	foreach my $i (@_) {
1020Sstevel@tonic-gate		push(@duff, $i)
1030Sstevel@tonic-gate		    if (! UNIVERSAL::isa($i, 'Sun::Solaris::Exacct::Object'));
1040Sstevel@tonic-gate	}
1050Sstevel@tonic-gate	if (@duff) {
1060Sstevel@tonic-gate		local $Carp::CarpLevel = 2;
1070Sstevel@tonic-gate		croak('"', join('", "', @duff), @duff == 1 ? '" is' : '" are',
1080Sstevel@tonic-gate		    ' not of type Sun::Solaris::Exacct::Object');
1090Sstevel@tonic-gate	}
1100Sstevel@tonic-gate}
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate#
1130Sstevel@tonic-gate# Tied hash access methods
1140Sstevel@tonic-gate#
1150Sstevel@tonic-gatesub TIEARRAY
1160Sstevel@tonic-gate{
1170Sstevel@tonic-gate	return(bless([], $_[0]));
1180Sstevel@tonic-gate}
1190Sstevel@tonic-gate
1200Sstevel@tonic-gatesub FETCHSIZE
1210Sstevel@tonic-gate{
1220Sstevel@tonic-gate	return(scalar(@{$_[0]}));
1230Sstevel@tonic-gate}
1240Sstevel@tonic-gate
1250Sstevel@tonic-gatesub STORESIZE
1260Sstevel@tonic-gate{
1270Sstevel@tonic-gate	$#{$_[0]} = $_[1] - 1;
1280Sstevel@tonic-gate}
1290Sstevel@tonic-gate
1300Sstevel@tonic-gatesub STORE
1310Sstevel@tonic-gate{
1320Sstevel@tonic-gate	check_args($_[2]);
1330Sstevel@tonic-gate	return($_[0]->[$_[1]] = copy_xs_ea_objects($_[2]));
1340Sstevel@tonic-gate}
1350Sstevel@tonic-gate
1360Sstevel@tonic-gatesub FETCH
1370Sstevel@tonic-gate{
1380Sstevel@tonic-gate	return($_[0]->[$_[1]]);
1390Sstevel@tonic-gate}
1400Sstevel@tonic-gate
1410Sstevel@tonic-gatesub CLEAR
1420Sstevel@tonic-gate{
1430Sstevel@tonic-gate	@{$_[0]} = ();
1440Sstevel@tonic-gate}
1450Sstevel@tonic-gate
1460Sstevel@tonic-gatesub POP
1470Sstevel@tonic-gate{
1480Sstevel@tonic-gate	return(pop(@{$_[0]}));
1490Sstevel@tonic-gate}
1500Sstevel@tonic-gate
1510Sstevel@tonic-gatesub PUSH
1520Sstevel@tonic-gate{
1530Sstevel@tonic-gate	my $a = shift(@_);
1540Sstevel@tonic-gate	check_args(@_);
1550Sstevel@tonic-gate	push(@$a, copy_xs_ea_objects(@_));
1560Sstevel@tonic-gate}
1570Sstevel@tonic-gate
1580Sstevel@tonic-gatesub SHIFT
1590Sstevel@tonic-gate{
1600Sstevel@tonic-gate	return(shift(@{$_[0]}));
1610Sstevel@tonic-gate}
1620Sstevel@tonic-gate
1630Sstevel@tonic-gatesub UNSHIFT
1640Sstevel@tonic-gate{
1650Sstevel@tonic-gate	my $a = shift(@_);
1660Sstevel@tonic-gate	check_args($_[2]);
1670Sstevel@tonic-gate	return(unshift(@$a, copy_xs_ea_objects(@_)));
1680Sstevel@tonic-gate}
1690Sstevel@tonic-gate
1700Sstevel@tonic-gatesub EXISTS
1710Sstevel@tonic-gate{
1720Sstevel@tonic-gate	return(exists($_[0]->[$_[1]]));
1730Sstevel@tonic-gate}
1740Sstevel@tonic-gate
1750Sstevel@tonic-gatesub DELETE
1760Sstevel@tonic-gate{
1770Sstevel@tonic-gate	return(delete($_[0]->[$_[1]]));
1780Sstevel@tonic-gate}
1790Sstevel@tonic-gate
1800Sstevel@tonic-gatesub EXTEND
1810Sstevel@tonic-gate{
1820Sstevel@tonic-gate}
1830Sstevel@tonic-gate
1840Sstevel@tonic-gatesub SPLICE
1850Sstevel@tonic-gate{
1860Sstevel@tonic-gate	my $a = shift(@_);
1870Sstevel@tonic-gate 	my $sz = scalar(@$a);
1880Sstevel@tonic-gate	my $off = @_ ? shift(@_) : 0;
1890Sstevel@tonic-gate	$off += $sz if $off < 0;
1900Sstevel@tonic-gate	my $len = @_ ? shift : $sz - $off;
1910Sstevel@tonic-gate	check_args(@_);
1920Sstevel@tonic-gate	return(splice(@$a, $off, $len, copy_xs_ea_objects(@_)));
1930Sstevel@tonic-gate}
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate1;
196