4555 macro side-effects with /usr/include/libelf.h
[illumos-gate.git] / usr / src / cmd / perl / contrib / Sun / Solaris / Exacct / Object / Object.pm
blobd083e1b3deb993ab60a41844ed1a296c6eb755b5
2 # Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
6 # Object.pm contains perl code for exacct object manipulation.
9 require 5.8.4;
10 use strict;
11 use warnings;
13 package Sun::Solaris::Exacct::Object;
15 our $VERSION = '1.3';
16 use XSLoader;
17 XSLoader::load(__PACKAGE__, $VERSION);
19 our (@EXPORT_OK, %EXPORT_TAGS, @_Constants);
20 @EXPORT_OK = @_Constants;
21 %EXPORT_TAGS = (CONSTANTS => \@_Constants, ALL => \@EXPORT_OK);
23 use base qw(Exporter);
24 use Sun::Solaris::Exacct::Catalog qw(:CONSTANTS);
27 # Class methods
31 # Dump an exacct object to the specified filehandle, or STDOUT by default.
33 sub dump
35 # Fettle parameters.
36 my ($class, $obj, $fh, $indent) = @_;
37 $fh ||= \*STDOUT;
38 $indent ||= 0;
39 my $istr = ' ' x $indent;
41 # Check for undef values.
42 if (! defined($obj)) {
43 print $fh ($istr, "UNDEFINED_VALUE\n");
44 return;
47 # Deal with items.
48 my @cat = $obj->catalog()->value();
49 if ($obj->type() == &EO_ITEM) {
50 printf $fh ("%sITEM\n%s Catalog = %s|%s|%s\n",
51 $istr, $istr, @cat);
52 $indent++;
53 my $val = $obj->value();
55 # Recursively dump nested objects.
56 if (ref($val)) {
57 $class->dump($val, $fh, $indent);
59 # Just print out items.
60 } else {
61 $val = unpack('H*', $val) if ($cat[0] == &EXT_RAW);
62 printf $fh ("%s Value = %s\n", $istr, $val);
65 # Deal with groups.
66 } else {
67 printf $fh ("%sGROUP\n%s Catalog = %s|%s|%s\n",
68 $istr, $istr, @cat);
69 $indent++;
70 foreach my $val ($obj->value()) {
71 $class->dump($val, $fh, $indent);
73 printf $fh ("%sENDGROUP\n", $istr);
78 # Item subclass - establish inheritance.
80 package Sun::Solaris::Exacct::Object::Item;
81 use base qw(Sun::Solaris::Exacct::Object);
84 # Group subclass - establish inheritance.
86 package Sun::Solaris::Exacct::Object::Group;
87 use base qw(Sun::Solaris::Exacct::Object);
90 # Tied array used for holding a group's items.
92 package Sun::Solaris::Exacct::Object::_Array;
93 use Carp;
96 # Check the passed list of arguments are derived from ::Object
98 sub check_args
100 my @duff;
101 foreach my $i (@_) {
102 push(@duff, $i)
103 if (! UNIVERSAL::isa($i, 'Sun::Solaris::Exacct::Object'));
105 if (@duff) {
106 local $Carp::CarpLevel = 2;
107 croak('"', join('", "', @duff), @duff == 1 ? '" is' : '" are',
108 ' not of type Sun::Solaris::Exacct::Object');
113 # Tied hash access methods
115 sub TIEARRAY
117 return(bless([], $_[0]));
120 sub FETCHSIZE
122 return(scalar(@{$_[0]}));
125 sub STORESIZE
127 $#{$_[0]} = $_[1] - 1;
130 sub STORE
132 check_args($_[2]);
133 return($_[0]->[$_[1]] = copy_xs_ea_objects($_[2]));
136 sub FETCH
138 return($_[0]->[$_[1]]);
141 sub CLEAR
143 @{$_[0]} = ();
146 sub POP
148 return(pop(@{$_[0]}));
151 sub PUSH
153 my $a = shift(@_);
154 check_args(@_);
155 push(@$a, copy_xs_ea_objects(@_));
158 sub SHIFT
160 return(shift(@{$_[0]}));
163 sub UNSHIFT
165 my $a = shift(@_);
166 check_args($_[2]);
167 return(unshift(@$a, copy_xs_ea_objects(@_)));
170 sub EXISTS
172 return(exists($_[0]->[$_[1]]));
175 sub DELETE
177 return(delete($_[0]->[$_[1]]));
180 sub EXTEND
184 sub SPLICE
186 my $a = shift(@_);
187 my $sz = scalar(@$a);
188 my $off = @_ ? shift(@_) : 0;
189 $off += $sz if $off < 0;
190 my $len = @_ ? shift : $sz - $off;
191 check_args(@_);
192 return(splice(@$a, $off, $len, copy_xs_ea_objects(@_)));