Exacct.pm revision 8287:771477e4b843
1# CDDL HEADER START
2#
3# The contents of this file are subject to the terms of the
4# Common Development and Distribution License (the "License").
5# You may not use this file except in compliance with the License.
6#
7# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8# or http://www.opensolaris.org/os/licensing.
9# See the License for the specific language governing permissions
10# and limitations under the License.
11#
12# When distributing Covered Code, include this CDDL HEADER in each
13# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14# If applicable, add the following below this CDDL HEADER, with the
15# fields enclosed by brackets "[]" replaced with your own identifying
16# information: Portions Copyright [yyyy] [name of copyright owner]
17#
18# CDDL HEADER END
19#
20
21#
22# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25
26#
27# Exacct.pm contains wrappers for the exacct error functions and syscalls,
28# and some 'shorthand' convenience functions.
29#
30
31require 5.8.4;
32use strict;
33use warnings;
34
35package Sun::Solaris::Exacct;
36
37our $VERSION = '1.5';
38use XSLoader;
39XSLoader::load(__PACKAGE__, $VERSION);
40
41# @_Constants is set up by the XSUB bootstrap() function.
42our (@EXPORT_OK, %EXPORT_TAGS, @_Constants);
43my @syscalls = qw(getacct putacct wracct);
44my @libcalls = qw(ea_error ea_error_str);
45my @shorthand = qw(ea_register_catalog ea_new_catalog ea_new_file ea_new_item
46    ea_new_group ea_dump_object);
47@EXPORT_OK = (@_Constants, @syscalls, @libcalls, @shorthand);
48%EXPORT_TAGS = (CONSTANTS => \@_Constants, SYSCALLS => \@syscalls,
49    LIBCALLS => \@libcalls, SHORTHAND => \@shorthand, ALL => \@EXPORT_OK);
50
51use base qw(Exporter);
52
53#
54# Extend the default Exporter::import to do optional inclusion of all the
55# lower-level Exacct modules.  Any export tag prefixed with 'EXACCT_' is
56# interpreted as a request to import that tag from all the Exacct modules.
57#
58sub import
59{
60	my (@my_tags, %sub_tags);
61	shift(@_);
62	foreach my $tag (@_) {
63		# Note: Modifies @_
64		if ($tag =~ /^:EXACCT_(.*)$/) {
65			my $new_tag = ":$1";
66			push(@my_tags, $new_tag);
67			$sub_tags{$new_tag} = 1;
68		} else {
69			push(@my_tags, $tag);
70		}
71	}
72
73	# Export the taglist with all "EXACCT_" prefixes removed.
74	__PACKAGE__->export_to_level(1, undef, @my_tags);
75
76	# Do sub-module imports if required.
77	if (@my_tags = grep(exists($sub_tags{$_}), qw(:ALL :CONSTANTS))) {
78
79		# ::Catalog
80		require Sun::Solaris::Exacct::Catalog;
81		Sun::Solaris::Exacct::Catalog->export_to_level(1, undef,
82		    @my_tags);
83
84		# ::File and Fcntl
85		require Sun::Solaris::Exacct::File;
86		Sun::Solaris::Exacct::File->export_to_level(1, undef,
87		    @my_tags);
88		require Fcntl;
89		Fcntl->export_to_level(1, undef, ':DEFAULT');
90
91		# ::Object
92		require Sun::Solaris::Exacct::Object;
93		Sun::Solaris::Exacct::Object->export_to_level(1, undef,
94		    @my_tags);
95	}
96}
97
98#
99# Convenience functions - shorthand for fully qualified method names.  Note that
100# goto() is used to call the methods so that any errors will appear to come
101# from the correct place.  Because goto() does not understand method call syntax
102# it is necessary to fake up the class a parameter by unshifting the appropriate
103# class name onto the argument lists.
104#
105
106sub ea_register_catalog
107{
108	unshift(@_, 'Sun::Solaris::Exacct::Catalog');
109	goto(&Sun::Solaris::Exacct::Catalog::register);
110}
111
112sub ea_new_catalog
113{
114	unshift(@_, 'Sun::Solaris::Exacct::Catalog');
115	goto(&Sun::Solaris::Exacct::Catalog::new);
116}
117
118sub ea_new_file
119{
120	unshift(@_, 'Sun::Solaris::Exacct::File');
121	goto(&Sun::Solaris::Exacct::File::new);
122}
123
124sub ea_new_item
125{
126	unshift(@_, 'Sun::Solaris::Exacct::Item');
127	goto(&Sun::Solaris::Exacct::Object::Item::new);
128}
129
130sub ea_new_group
131{
132	unshift(@_, 'Sun::Solaris::Exacct::Group');
133	goto(&Sun::Solaris::Exacct::Object::Group::new);
134}
135
136sub ea_dump_object
137{
138	unshift(@_, 'Sun::Solaris::Exacct::Object');
139	goto(&Sun::Solaris::Exacct::Object::dump);
140}
141
1421;
143