aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rwxr-xr-xmodules/renrot_dir.pm47
-rwxr-xr-xmodules/renrot_msg.pm86
2 files changed, 133 insertions, 0 deletions
diff --git a/modules/renrot_dir.pm b/modules/renrot_dir.pm
new file mode 100755
index 0000000..701b9c4
--- /dev/null
+++ b/modules/renrot_dir.pm
@@ -0,0 +1,47 @@
+use strict;
+
+package renrot_dir;
+
+###################################################
+# Usage : $a = new renrot_dir;
+# Purpose : allocator and initializer
+# Returns : initialized class
+# Parameters : none
+# Throws : no exceptions
+# Comments : none
+# See Also : n/a
+sub new {
+ my ($pkg, $dir, $ext) = @_;
+ my @files = ();
+ return (bless {dir => $dir,
+ ext => $ext,
+ files => \@files}, $pkg);
+}
+
+###################################################
+# Usage : none
+# Purpose : destructor
+# Returns : none
+# Parameters : none
+# Throws : no exceptions
+# Comments : none
+# See Also : n/a
+sub DESTROY {
+ my $obj = shift;
+ #print "\$obj->{", $obj->{dir}, "} has been destroied.\n";
+}
+
+###################################################
+# Usage : $obj->filename($base, $ext)
+# Purpose : full file name compilator: base . ext = baseext
+# Returns : ful filename
+# Parameters : 1. basename; 2. extention of ".ext" format
+# Throws : no exceptions
+# Comments : none
+# See Also : n/a
+sub file_name {
+ my ($obj, $base, $ext) = @_;
+ return $obj->{filename} = $base . $ext;
+}
+
+1;
diff --git a/modules/renrot_msg.pm b/modules/renrot_msg.pm
new file mode 100755
index 0000000..2b16f88
--- /dev/null
+++ b/modules/renrot_msg.pm
@@ -0,0 +1,86 @@
+use strict;
+
+use Term::ANSIColor;
+
+package msg;
+
+sub new {
+ my $obj = shift;
+ my $use_color = shift;
+ my $quiet = shift;
+ my $verbose = shift;
+ my %colors = (
+ debug => {value => 'green'},
+ error => {value => 'magenta'},
+ fatal => {value => 'red'},
+ info => {value => 'bold'},
+ process => {value => 'white'},
+ warning => {value => 'cyan'},
+ );
+ return (bless {use_color => $use_color,
+ quiet => $quiet,
+ verbose => $verbose,
+ colors => \%colors,
+ }, $obj);
+ #$obj->Dbg(4,"msg class has been created.\n");
+}
+# destructor
+sub DESTROY {
+ my $obj = shift;
+ #$obj->Dbg(4,"msg class has been destroied.\n");
+}
+# Prints colored message to STDERR
+sub coloredprn {
+ my $obj = shift;
+ my $facility = shift;
+ if ($obj->{use_color} != 0) {
+ if (defined $facility and defined $obj->{colors}{$facility}) {
+ print STDERR Term::ANSIColor::colored [$obj->{colors}{$facility}{value}], @_;
+ return;
+ }
+ }
+ print STDERR @_; # fallback to normal print
+}
+# processing message
+sub Proc {
+ my $obj = shift;
+ return if ($obj->{quiet} != 0);
+
+ if ($obj->{use_color} != 0) {
+ if (defined $obj->{colors}{'process'}) {
+ print Term::ANSIColor::colored [$obj->{colors}{'process'}{value}], @_;
+ return;
+ }
+ }
+ print @_; # fallback to normal print
+}
+# information message
+sub Info {
+ my $obj = shift;
+ $obj->coloredprn('info', @_);
+}
+# warning message
+sub Warn {
+ my $obj = shift;
+ $obj->coloredprn('warning', "Warning: ", @_);
+}
+# error message
+sub Err {
+ my $obj = shift;
+ $obj->coloredprn('error', "ERROR: ", @_);
+}
+# fatal message
+sub Fatal {
+ my $obj = shift;
+ $obj->coloredprn('fatal', "FATAL: ", @_);
+}
+# debug message
+sub Dbg {
+ my $obj = shift;
+ my $level = shift;
+ if ($obj->{verbose} >= $level) {
+ $obj->coloredprn('debug', "DEBUG[$level]: ", @_);
+ }
+}
+
+1;

Return to:

Send suggestions and report system problems to the System administrator.