1# 2# Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. 3# 4 5# 6# Exacct.pm contains wrappers for the exacct error functions and syscalls, 7# and some 'shorthand' convenience functions. 8# 9 10require 5.8.4; 11use strict; 12use warnings; 13 14package Sun::Solaris::Exacct; 15 16our $VERSION = '1.5'; 17use XSLoader; 18XSLoader::load(__PACKAGE__, $VERSION); 19 20# @_Constants is set up by the XSUB bootstrap() function. 21our (@EXPORT_OK, %EXPORT_TAGS, @_Constants); 22my @syscalls = qw(getacct putacct wracct); 23my @libcalls = qw(ea_error ea_error_str); 24my @shorthand = qw(ea_register_catalog ea_new_catalog ea_new_file ea_new_item 25 ea_new_group ea_dump_object); 26@EXPORT_OK = (@_Constants, @syscalls, @libcalls, @shorthand); 27%EXPORT_TAGS = (CONSTANTS => \@_Constants, SYSCALLS => \@syscalls, 28 LIBCALLS => \@libcalls, SHORTHAND => \@shorthand, ALL => \@EXPORT_OK); 29 30use base qw(Exporter); 31 32# 33# Extend the default Exporter::import to do optional inclusion of all the 34# lower-level Exacct modules. Any export tag prefixed with 'EXACCT_' is 35# interpreted as a request to import that tag from all the Exacct modules. 36# 37sub import 38{ 39 my (@my_tags, %sub_tags); 40 shift(@_); 41 foreach my $tag (@_) { 42 # Note: Modifies @_ 43 if ($tag =~ /^:EXACCT_(.*)$/) { 44 my $new_tag = ":$1"; 45 push(@my_tags, $new_tag); 46 $sub_tags{$new_tag} = 1; 47 } else { 48 push(@my_tags, $tag); 49 } 50 } 51 52 # Export the taglist with all "EXACCT_" prefixes removed. 53 __PACKAGE__->export_to_level(1, undef, @my_tags); 54 55 # Do sub-module imports if required. 56 if (@my_tags = grep(exists($sub_tags{$_}), qw(:ALL :CONSTANTS))) { 57 58 # ::Catalog 59 require Sun::Solaris::Exacct::Catalog; 60 Sun::Solaris::Exacct::Catalog->export_to_level(1, undef, 61 @my_tags); 62 63 # ::File and Fcntl 64 require Sun::Solaris::Exacct::File; 65 Sun::Solaris::Exacct::File->export_to_level(1, undef, 66 @my_tags); 67 require Fcntl; 68 Fcntl->export_to_level(1, undef, ':DEFAULT'); 69 70 # ::Object 71 require Sun::Solaris::Exacct::Object; 72 Sun::Solaris::Exacct::Object->export_to_level(1, undef, 73 @my_tags); 74 } 75} 76 77# 78# Convenience functions - shorthand for fully qualified method names. Note that 79# goto() is used to call the methods so that any errors will appear to come 80# from the correct place. Because goto() does not understand method call syntax 81# it is necessary to fake up the class a parameter by unshifting the appropriate 82# class name onto the argument lists. 83# 84 85sub ea_register_catalog 86{ 87 unshift(@_, 'Sun::Solaris::Exacct::Catalog'); 88 goto(&Sun::Solaris::Exacct::Catalog::register); 89} 90 91sub ea_new_catalog 92{ 93 unshift(@_, 'Sun::Solaris::Exacct::Catalog'); 94 goto(&Sun::Solaris::Exacct::Catalog::new); 95} 96 97sub ea_new_file 98{ 99 unshift(@_, 'Sun::Solaris::Exacct::File'); 100 goto(&Sun::Solaris::Exacct::File::new); 101} 102 103sub ea_new_item 104{ 105 unshift(@_, 'Sun::Solaris::Exacct::Item'); 106 goto(&Sun::Solaris::Exacct::Object::Item::new); 107} 108 109sub ea_new_group 110{ 111 unshift(@_, 'Sun::Solaris::Exacct::Group'); 112 goto(&Sun::Solaris::Exacct::Object::Group::new); 113} 114 115sub ea_dump_object 116{ 117 unshift(@_, 'Sun::Solaris::Exacct::Object'); 118 goto(&Sun::Solaris::Exacct::Object::dump); 119} 120 1211; 122