xref: /onnv-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Exacct/Exacct.pm (revision 12388:1bc8d55b0dfd)
10Sstevel@tonic-gate#
2*12388SJohn.Sonnenschein@Sun.COM# Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
37298SMark.J.Nelson@Sun.COM#
47298SMark.J.Nelson@Sun.COM
50Sstevel@tonic-gate#
60Sstevel@tonic-gate# Exacct.pm contains wrappers for the exacct error functions and syscalls,
70Sstevel@tonic-gate# and some 'shorthand' convenience functions.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate
108287SJohn.Sonnenschein@Sun.COMrequire 5.8.4;
110Sstevel@tonic-gateuse strict;
120Sstevel@tonic-gateuse warnings;
130Sstevel@tonic-gate
140Sstevel@tonic-gatepackage Sun::Solaris::Exacct;
150Sstevel@tonic-gate
167298SMark.J.Nelson@Sun.COMour $VERSION = '1.5';
170Sstevel@tonic-gateuse XSLoader;
180Sstevel@tonic-gateXSLoader::load(__PACKAGE__, $VERSION);
190Sstevel@tonic-gate
200Sstevel@tonic-gate# @_Constants is set up by the XSUB bootstrap() function.
210Sstevel@tonic-gateour (@EXPORT_OK, %EXPORT_TAGS, @_Constants);
220Sstevel@tonic-gatemy @syscalls = qw(getacct putacct wracct);
230Sstevel@tonic-gatemy @libcalls = qw(ea_error ea_error_str);
240Sstevel@tonic-gatemy @shorthand = qw(ea_register_catalog ea_new_catalog ea_new_file ea_new_item
250Sstevel@tonic-gate    ea_new_group ea_dump_object);
260Sstevel@tonic-gate@EXPORT_OK = (@_Constants, @syscalls, @libcalls, @shorthand);
270Sstevel@tonic-gate%EXPORT_TAGS = (CONSTANTS => \@_Constants, SYSCALLS => \@syscalls,
280Sstevel@tonic-gate    LIBCALLS => \@libcalls, SHORTHAND => \@shorthand, ALL => \@EXPORT_OK);
290Sstevel@tonic-gate
300Sstevel@tonic-gateuse base qw(Exporter);
310Sstevel@tonic-gate
320Sstevel@tonic-gate#
330Sstevel@tonic-gate# Extend the default Exporter::import to do optional inclusion of all the
340Sstevel@tonic-gate# lower-level Exacct modules.  Any export tag prefixed with 'EXACCT_' is
350Sstevel@tonic-gate# interpreted as a request to import that tag from all the Exacct modules.
360Sstevel@tonic-gate#
370Sstevel@tonic-gatesub import
380Sstevel@tonic-gate{
390Sstevel@tonic-gate	my (@my_tags, %sub_tags);
400Sstevel@tonic-gate	shift(@_);
410Sstevel@tonic-gate	foreach my $tag (@_) {
420Sstevel@tonic-gate		# Note: Modifies @_
430Sstevel@tonic-gate		if ($tag =~ /^:EXACCT_(.*)$/) {
440Sstevel@tonic-gate			my $new_tag = ":$1";
450Sstevel@tonic-gate			push(@my_tags, $new_tag);
460Sstevel@tonic-gate			$sub_tags{$new_tag} = 1;
470Sstevel@tonic-gate		} else {
480Sstevel@tonic-gate			push(@my_tags, $tag);
490Sstevel@tonic-gate		}
500Sstevel@tonic-gate	}
510Sstevel@tonic-gate
520Sstevel@tonic-gate	# Export the taglist with all "EXACCT_" prefixes removed.
530Sstevel@tonic-gate	__PACKAGE__->export_to_level(1, undef, @my_tags);
540Sstevel@tonic-gate
550Sstevel@tonic-gate	# Do sub-module imports if required.
560Sstevel@tonic-gate	if (@my_tags = grep(exists($sub_tags{$_}), qw(:ALL :CONSTANTS))) {
570Sstevel@tonic-gate
580Sstevel@tonic-gate		# ::Catalog
590Sstevel@tonic-gate		require Sun::Solaris::Exacct::Catalog;
600Sstevel@tonic-gate		Sun::Solaris::Exacct::Catalog->export_to_level(1, undef,
610Sstevel@tonic-gate		    @my_tags);
620Sstevel@tonic-gate
630Sstevel@tonic-gate		# ::File and Fcntl
640Sstevel@tonic-gate		require Sun::Solaris::Exacct::File;
650Sstevel@tonic-gate		Sun::Solaris::Exacct::File->export_to_level(1, undef,
660Sstevel@tonic-gate		    @my_tags);
670Sstevel@tonic-gate		require Fcntl;
680Sstevel@tonic-gate		Fcntl->export_to_level(1, undef, ':DEFAULT');
690Sstevel@tonic-gate
700Sstevel@tonic-gate		# ::Object
710Sstevel@tonic-gate		require Sun::Solaris::Exacct::Object;
720Sstevel@tonic-gate		Sun::Solaris::Exacct::Object->export_to_level(1, undef,
730Sstevel@tonic-gate		    @my_tags);
740Sstevel@tonic-gate	}
750Sstevel@tonic-gate}
760Sstevel@tonic-gate
770Sstevel@tonic-gate#
780Sstevel@tonic-gate# Convenience functions - shorthand for fully qualified method names.  Note that
790Sstevel@tonic-gate# goto() is used to call the methods so that any errors will appear to come
800Sstevel@tonic-gate# from the correct place.  Because goto() does not understand method call syntax
810Sstevel@tonic-gate# it is necessary to fake up the class a parameter by unshifting the appropriate
820Sstevel@tonic-gate# class name onto the argument lists.
830Sstevel@tonic-gate#
840Sstevel@tonic-gate
850Sstevel@tonic-gatesub ea_register_catalog
860Sstevel@tonic-gate{
870Sstevel@tonic-gate	unshift(@_, 'Sun::Solaris::Exacct::Catalog');
880Sstevel@tonic-gate	goto(&Sun::Solaris::Exacct::Catalog::register);
890Sstevel@tonic-gate}
900Sstevel@tonic-gate
910Sstevel@tonic-gatesub ea_new_catalog
920Sstevel@tonic-gate{
930Sstevel@tonic-gate	unshift(@_, 'Sun::Solaris::Exacct::Catalog');
940Sstevel@tonic-gate	goto(&Sun::Solaris::Exacct::Catalog::new);
950Sstevel@tonic-gate}
960Sstevel@tonic-gate
970Sstevel@tonic-gatesub ea_new_file
980Sstevel@tonic-gate{
990Sstevel@tonic-gate	unshift(@_, 'Sun::Solaris::Exacct::File');
1000Sstevel@tonic-gate	goto(&Sun::Solaris::Exacct::File::new);
1010Sstevel@tonic-gate}
1020Sstevel@tonic-gate
1030Sstevel@tonic-gatesub ea_new_item
1040Sstevel@tonic-gate{
1050Sstevel@tonic-gate	unshift(@_, 'Sun::Solaris::Exacct::Item');
1060Sstevel@tonic-gate	goto(&Sun::Solaris::Exacct::Object::Item::new);
1070Sstevel@tonic-gate}
1080Sstevel@tonic-gate
1090Sstevel@tonic-gatesub ea_new_group
1100Sstevel@tonic-gate{
1110Sstevel@tonic-gate	unshift(@_, 'Sun::Solaris::Exacct::Group');
1120Sstevel@tonic-gate	goto(&Sun::Solaris::Exacct::Object::Group::new);
1130Sstevel@tonic-gate}
1140Sstevel@tonic-gate
1150Sstevel@tonic-gatesub ea_dump_object
1160Sstevel@tonic-gate{
1170Sstevel@tonic-gate	unshift(@_, 'Sun::Solaris::Exacct::Object');
1180Sstevel@tonic-gate	goto(&Sun::Solaris::Exacct::Object::dump);
1190Sstevel@tonic-gate}
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate1;
122