Conf.pm

filter: Statementstmt 59.2% 16 / 27 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 1 / 1 totaltotal 59.4% 22 / 37 CC 1 SCAR 3.7
CC
1
Cov
59%
debuglevel
2.0
_open_conf
2.0
_release_all
2.0
CRAP 1.4
« Conf/Err.pm ↑ Summary
1 # Provides utility modules for use by file configuration manipulation classes
2 #
3 # Copyright Karthik Krishnamurthy <karthik.k@extremix.net>
4  
5 =head1 NAME
6  
7 Unix::Conf - Front end for class methods in various utility modules
8 under the Unix::Conf namespace.
9  
10 =head1 DESCRIPTION
11  
12 Methods in Unix::Conf are intended as a gateway into the various
13 utility modules like Unix::Conf::ConfIO, Unix::Conf::Err. Unix::Conf
14 is the preferred way to access class constructors in the above mentioned
15 modules. Methods starting with a '_' are intended for use from other
16 modules under the Unix::Conf namespace. Those without the '_' prefix
17 are for general users of the Unix::Conf suite of modules.
18  
19 =head1 METHODS
20  
21 =cut
22  
23 package Unix::Conf;
24  
25 1 ▶use 5.6.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Unix::Conf::Err;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Unix::Conf::ConfIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 $Unix::Conf::VERSION = "0.2";
32  
33 =over 4
34  
35 =item debuglevel ()
36  
37 Arguments
38 DEBUGLEVEL,
39 Set the class debuglevel variable in Unix::Conf::Err. This enables
40 debugging messages to be printed for all class objects. The actual
41 level at which debug messages are printed is the maximum of class
42 debuglevel variable and the object specific debuglevel variable.
43 Refer to Unix::Conf::Err for the behaviour of the three debuglevels.
44  
45 Example
46 Unix::Conf->debuglevel (2);
47  
48 =cut
49  
50 sub debuglevel
51 0 ▶{
Subroutine debuglevel: not called CC=1 SCAR=6.9
Pod documented
52 0 shift ();
53 0 return (Unix::Conf::Err->debuglevel (@_));
54 }
55  
56 =item _open_conf ()
57  
58 Arguments
59 NAME => 'PATHNAME',
60 MODE => FILE_OPEN_MODE, # default is O_RDWR | O_CREAT
61 PERMS => FILE_CREATION_PERMS,# default is 0600
62 LOCK_STYLE => 'flock'/'dotlock', # default is 'flock'
63 SECURE_OPEN => 0/1, # default is 0 (disabled)
64 PERSIST=> 0/1, # default is 0 (disabled)
65 Open a configuration file and return a Unix::Conf::ConfIO object.
66 A LOCK_STYLE of 'dotlock' is used to access /etc/passwd,
67 /etc/shadow, /etc/group, /etc/gshadow. Refer to Unix::Conf::ConfIO
68 for the various methods that this object offers. Returns a new
69 ConfIO object in case of success, or an Err object in case of
70 failure. Refer to documentation for
71  
72 Example
73 my $conf = Unix::Conf->_open_conf (
74 NAME => '/etc/passwd',
75 SECURE_OPEN => 1,
76 LOCK_STYLE => 'dotlock',
77 );
78  
79 =cut
80  
81 # For use by other modules only. use goto &funcname to warp to that function
82 # replacing the frame for these functions. The actual functions/methods meddle
83 # with the stack and hence are sensitive to the calling sequence. We could
84 # alter those methods to omit one frame, i.e. that of Unix::Conf->_*. However
85 # this way, even if users call Unix::Conf::Err, or Unix::Conf::ConfIO directly,
86 # it will still work
87 sub _open_conf
88 0 ▶{
Subroutine _open_conf: not called CC=1 SCAR=6.9
89 0 shift ();
90 0 unshift (@_, 'Unix::Conf::ConfIO');
91 0 goto &Unix::Conf::ConfIO::open;
92 }
93  
94 =item _release_all ()
95  
96 Release all objects which have been opened persistently by the
97 calling class.
98  
99 Example
100 my $conf = Unix::Conf->_open_conf (
101 NAME => 'some_conf',
102 PERSISTENT => 1,
103 LOCK => 'flock',
104 );
105 # Now this object will be held in the Unix:Conf::ConfIO
106 # object cache even though $conf passes out of scope.
107 # This is for ancillary files which need to be held open
108 # so that they remain locked. It eases the user from
109 # having to prevent the user of these objects from going
110 # out of scope. Call this from the destructor to release
111 # all such objects.
112  
113 sub DESTROY
114 {
115 # do stuff
116 Unix::Conf->_release_all ();
117 }
118  
119 # Now all persistently held Unix::Conf::ConfIO objects
120 # will be released this triggering their destructors
121 # which will effectively sync the files and release
122 # the locks.
123  
124 =cut
125  
126 sub _release_all
127 0 ▶{
Subroutine _release_all: not called CC=1 SCAR=6.9
128 0 shift ();
129 0 unshift (@_, 'Unix::Conf::ConfIO');
130 0 goto &Unix::Conf::ConfIO::release_all;
131 }
132  
133 =item _err ()
134  
135 Arguments
136 PREFIX,
137 ERRMSG,
138 Create a new Unix::Conf::Err object. This object remembers the stack
139 at the creation. The returned object can thrown or returned to
140 indicate an error condition as it evaluates to false in a boolean
141 context. Refer to Unix::Conf::Err for the various methods that this
142 object offers. If error message is missing, a stringified version of
143 $! is stored as the error message.
144  
145 Example
146 return (Unix::Conf::->_err ('chdir')) unless (chdir ('/etc'));
147  
148 return (
149 Unix::Conf::->_err (
150 'object_method', 'argument not an object of class BLAH'
151 )
152 ) unless (ref ($obj) eq 'BLAH');
153  
154 =cut
155  
156 sub _err
157 0 ▶{
Subroutine _err: not called CC=1 SCAR=6.9
158 0 shift ();
159 0 unshift (@_, 'Unix::Conf::Err');
160 0 goto &Unix::Conf::Err::new;
161 }
162  
163 1 1;
164 __END__
« Conf/Err.pm ↑ Summary