This file is indexed.

/usr/share/perl5/OpaL/action.pm is in opalmod 0.2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/perl
#    OpaL Perl Modules
#    Copyright (C) 2000,2007-2008  Ola Lundqvist <ola@inguza.com>
#
#    For full COPYRIGHT notice see the COPYING document.
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of either:
#
#	a) the GNU General Public License as published by the Free
#	Software Foundation; either version 1, or (at your option) any
#	later version, or
#
#	b) the "Artistic License" which comes with this Kit.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either
#    the GNU General Public License or the Artistic License for more details.
#
#
#    For more information take a look at the official homepage at:
#      http://inguza.com/software/opalmod
#    or contact the author at:
#      ola@inguza.com
#

package OpaL::action;

#use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
use POSIX qw(strftime);

require Exporter;

@ISA = qw(Exporter AutoLoader);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw();
@EXPORT_OK = qw(pdebug exitlvl action cmdaction
		setDebugLevel setQuitLevel
		getDebugLevel getQuitLevel
		setErrorHandler);

# If you are using CVS/RCS this can be quite handy.
#$VERSION = do{my@r=q$Revision: 1.31 $=~/\d+/g;sprintf '%d.'.'%02d'x$#r,@r};

# If that is not what you want use this instead. Will be rewritten by
# create release.
my $version = '0.01';
$VERSION = $version;

###############################################################################
############################ PACKAGE GLOBALS ##################################
###############################################################################
# First exported ones (those in @EXPORT or @EXPORT_OK)
# No exportet variables.

# Then package other global ones. (not exported ones)
# Can be accessed through $OpaL::action::variablename
# No such too.

# All file-scooped variables must be created before any method that uses them.
my %ERRLVL =
    (
     1 => 'Critical',
     2 => 'Error',
     3 => 'Warning',
     4 => 'Message',
     5 => 'Debug'
     );

my $debuglvl = 3;
my $qlvl = 2;
my $errorHandler;

###############################################################################
########################### PRELOADED METHODS #################################
###############################################################################
# Preloaded methods go here.

###############################################################################
# Name:		setErrorHandler
# Description:	Sets the error handler function.
# Arguments:	$function (no arguments).
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2002-01-22
###############################################################################
sub setErrorHandler (&) {
    ($errorHandler) = @_;
}

###############################################################################
# Name:		setDebugLevel
# Description:	Sets the debug level to something.
# Arguments:	$level (1 to 5)
# Changes:	The localy scooped $debuglvl
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-05-01
###############################################################################
sub setDebugLevel ($) {
    $debuglvl = shift;
}

###############################################################################
# Name:		getDebugLevel
# Description:	returns the debug level.
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-07-06
###############################################################################
sub getDebugLevel () {
    return $debuglvl;
}

###############################################################################
# Name:		setQuitLevel
# Description:	Sets the quit level to something.
# Arguments:	$level (1 to 5)
# Changes:	The localy scooped $qlvl
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-05-01
###############################################################################
sub setQuitLevel ($) {
    $qlvl = shift;
}

###############################################################################
# Name:		getQuitLevel
# Description:	returns the quit level.
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-07-06
###############################################################################
sub getQuitLevel () {
    return $qlvl;
}

###############################################################################
# Name:		pdebug
# Description:	Prints a debug message and exit the program if the level are
#		to critical.
# Arguments:	$level, $message, [exit ref function]
# Uses:		exitlvl
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-05-01
#		2000-05-04	Minor modifications.
#		2000-06-27	Removed comment.
#		2002-01-22	Added exit ref function.
###############################################################################
sub pdebug ($$;&) {
    my ($lvl,$message,$ref) = @_;
    if ($debuglvl >= $lvl) {
	if ($message !~ /\n$/) {
	    $message = $message . "\n";
	}
	print ("$ERRLVL{$lvl}: $message");
    }
    exitlvl($lvl,$ref);
    return;
}

###############################################################################
# Name:		exitlvl
# Description:	Exit the program if the level are to critical.
# Arguments:	$level, [exit ref function]
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-05-01
#		2000-06-27	Added argument definition ($).
#		2002-01-22	Added exit ref function.
#               2009-03-16      Make sure to exit with error code and not 0.
###############################################################################
sub exitlvl ($;&) {
    my ($lvl, $ref) = @_;
    if ($qlvl >= $lvl) {
	if (! defined $ref) {
	    $ref = $errorHandler;
	}
	if (! defined $ref) {
	    print "EXIT: $lvl\n" if ($debuglvl >= $lvl);
	    exit $lvl;
	}
	if ($ref =~ /^$/ ||
	    $ref =~ /exit/i) {
	    print "EXIT: $lvl\n" if ($debuglvl >= $lvl);
	    exit $lvl;
	}
	elsif ("CODE" == ref $ref) {
	    &$ref;
	}
	elsif ("SCALAR" == ref $ref) {
	    &$ref;
	}
	else {
	    print "EXIT: $lvl\n" if ($debuglvl >= $lvl);
	    print("Really strange error handler: (".(ref $ref).") ".$ref);
	    exit $lvl;
	}
    }
}

###############################################################################
# Name:		action
# Description:	If eval is true then print out an error message.
# Arguments:	$eval, $message, [$errlvl default 2], [exit ref function]
# Uses:		pdebug
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-05-01
#		2000-06-27	Added a $ to make sure that errlvl is ok.
#				Added argument definition ($$:$).
#		2000-07-09	Layout changes and a bug fix. (From orat.)
#		2002-01-22	Added exit ref function.
###############################################################################
sub action ($$;$&) {
    my ($eval, $message, $errlvl,$ref) = @_;
    if ($errlvl =~ /^\s*$/) {
	$errlvl = 2;
    }
    if ($eval) {
	&pdebug($errlvl,"$message\n",$ref);
    }
    else {
	&pdebug(5,"$message\n",$ref);
    }
}

###############################################################################
# Name:		cmdaction
# Description:	If system(command) is erronious then call action.
# Arguments:	$command, $message, [$errorlevel default 2], [$quiet]
# Uses:		pdebug, action
# Author:	Ola Lundqvist <ola@inguza.com>
# Date:		2000-05-01
#		2000-05-19	Fixed quietcmd?
#		2000-06-27	Added a $ to make sure that errlvl is ok.
#				Added argument definition ($$:$).
#		2000-07-06	More readable argument getting.
#		2002-01-22	Better error handling.
###############################################################################
sub cmdaction ($$;$$&) {
    my ($cmd, $message, $errlvl, $qt, $ref) = @_;

    if ($errlvl =~ /^\s*$/) {
	$errlvl = 2;
    }
    if ($qt =~ /^\s*$/) {
	$qt = 0;
    }
    if ($message !~ /\n$/) {
	$message = $message . "\n";
    }
    &pdebug(4,$message);
    &pdebug(5,"CMD: $cmd\n");
    my $quietcmd = "";
    my $tcmd = $cmd;
    while ($tcmd =~ /\"[^\"]*\"/) {
	$tcmd =~ s/\"[^\"]*\"//;
    }
    if ($tcmd !~ />/) {
	$quietcmd = " \> /dev/null" if ($debuglvl == 4 || $qt == 1);
	$quietcmd = " \> /dev/null 2\>\&1" if ($debuglvl < 4);
	$quietcmd = "" if ($qt == 2);
    }
    &action(system("$cmd$quietcmd"),$message,$errlvl,$ref);
}

# Autoload methods go after =cut, and are processed by the autosplit program.

# Modules must return true.
1;
__END__

###############################################################################
############################# DOCUMENTATION ###################################
###############################################################################
# Below is the stub of documentation for your module. You better edit it!

=head1 NAME

OpaL::action - Perl extension for easier handling of what information that
should be presented when a action is made.

=head1 SYNOPSIS

  use OpaL::action qw(functionnames);

No functions or variables are exported automaticly so you have to specify
them here. 

=head1 DESCRIPTION

OpaL::action is a module to allow some better bugtracking and information to
be sent to the user/developer.

All functions are autoloaded so they will not be loaded into memory if you
have not used them before.

There are 5 different levels of the information/action.

=over 4

=item 1

critical

=item 2

error

=item 3

warning

=item 4

message

=item 5

debug

=back

=head1 FUNCTIONS

=over 4

=item B<setQuitLevel>

You can set on what errorlevel the program should exit if an error occur.
The default level is 2 and you canges it like this:

USAGE:
    C<setQuitLevel>(level);

=item B<setErrorHandler>

You can set an alternative error handler function (no arguments). The default
one is exit.

USAGE:
    C<setErrorHandler>(\funcname);

=item B<setDebugLevel>

You can set on what errorlevel the program should output messages if an error
occur. The debug level indicates what type of information that should be
presented to the user.
    
USAGE:
    C<setDebugLevel>(level);

=item B<getQuitLevel>

You can set on what errorlevel the program should exit if an error occur.

USAGE:
    $foo = C<getQuitLevel>;

=item B<getDebugLevel>

You can get the debuglevel on which the program should output messages, if an
error occurs.

USAGE:
    $foo = C<getDebugLevel>;

=item B<pdebug>

You can set on what errorlevel the program should exit if an error occur.
With the pdebug method you can present information and mark it with a
debuglevel using:

USAGE:
    C<pdebug>(level, "A sample informational text." [,funcref]);

=item B<action>

With this function you can handle and print a message if a function does
not work correctly.

It will exit the program and print a message with the error level before if
the action returns true and if the action_critic is lower or equal to the set
error level.

If the debug level is high enough it will present the message but without the
trailing error message.

USAGE:
    C<action>(some_action,
           "A sample informational text about the action.",
            how_critical [,funcref]);

The last parameter (how_critical) is optional.

=item B<cmdaction>

Actually the same as B<action> with the difference that it executes a external
command instead.

It is almost identical to action(system"a command to execute", ...);

USAGE:
    C<cmdaction>("a command to execute.",
              "A sample informational text about the action.",
               how_critical,
	       how_quiet [,funcref]);

The two last parameter (how_critical) is optional.
The last parameter tells how quiet the executing command should be:
  0 - extremely quiet (ie: >& /dev/null)
  1 - quiet           (ie: >& /dev/null)
  2 - everything sent to stdout.
=back

=head1 AUTHOR

Ola Lundqvist <ola@inguza.com>

=head1 SEE ALSO

perl(1).

=cut

###############################################################################
########################### AUTOLOAD METHODS ##################################
###############################################################################