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
10 require 5.8.4;
11 use strict;
12 use warnings;
13
14 package Sun::Solaris::Exacct;
15
16 our $VERSION = '1.5';
17 use XSLoader;
18 XSLoader::load(__PACKAGE__, $VERSION);
19
20 # @_Constants is set up by the XSUB bootstrap() function.
21 our (@EXPORT_OK, %EXPORT_TAGS, @_Constants);
22 my @syscalls = qw(getacct putacct wracct);
23 my @libcalls = qw(ea_error ea_error_str);
24 my @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
30 use 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 #
37 sub 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
85 sub ea_register_catalog
86 {
87 unshift(@_, 'Sun::Solaris::Exacct::Catalog');
88 goto(&Sun::Solaris::Exacct::Catalog::register);
89 }
90
91 sub ea_new_catalog
92 {
93 unshift(@_, 'Sun::Solaris::Exacct::Catalog');
94 goto(&Sun::Solaris::Exacct::Catalog::new);
95 }
96
97 sub ea_new_file
98 {
99 unshift(@_, 'Sun::Solaris::Exacct::File');
100 goto(&Sun::Solaris::Exacct::File::new);
101 }
102
103 sub ea_new_item
104 {
105 unshift(@_, 'Sun::Solaris::Exacct::Item');
106 goto(&Sun::Solaris::Exacct::Object::Item::new);
107 }
108
109 sub ea_new_group
110 {
111 unshift(@_, 'Sun::Solaris::Exacct::Group');
112 goto(&Sun::Solaris::Exacct::Object::Group::new);
113 }
114
115 sub ea_dump_object
116 {
117 unshift(@_, 'Sun::Solaris::Exacct::Object');
118 goto(&Sun::Solaris::Exacct::Object::dump);
119 }
120
121 1;