diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2001-07-24 16:53:54 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2001-07-24 16:53:54 +0000 |
commit | 5bef71a0c86613f95e154d08b5f8f0cc23226e27 (patch) | |
tree | 57150f236c56d435fbf76b092eab0a78007169c4 /MDK/Common/Various.pm | |
parent | d7cea7bcbafb212013a3638ee3e76d63e9ef18cc (diff) | |
download | perl-MDK-Common-5bef71a0c86613f95e154d08b5f8f0cc23226e27.tar perl-MDK-Common-5bef71a0c86613f95e154d08b5f8f0cc23226e27.tar.gz perl-MDK-Common-5bef71a0c86613f95e154d08b5f8f0cc23226e27.tar.bz2 perl-MDK-Common-5bef71a0c86613f95e154d08b5f8f0cc23226e27.tar.xz perl-MDK-Common-5bef71a0c86613f95e154d08b5f8f0cc23226e27.zip |
initial commit
Diffstat (limited to 'MDK/Common/Various.pm')
-rw-r--r-- | MDK/Common/Various.pm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/MDK/Common/Various.pm b/MDK/Common/Various.pm new file mode 100644 index 0000000..b012343 --- /dev/null +++ b/MDK/Common/Various.pm @@ -0,0 +1,32 @@ +package MDK::Common::Various; + +use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK); +@ISA = qw(Exporter); +@EXPORT_OK = qw(first second top bool to_int to_float bool2text bool2yesno text2bool chomp_ backtrace); +%EXPORT_TAGS = (all => [ @EXPORT_OK ]); + + +sub first { $_[0] } +sub second { $_[1] } +sub top { $_[-1] } + +sub bool { $_[0] ? 1 : 0 } +sub to_int { $_[0] =~ /(\d*)/; $1 } +sub to_float { $_[0] =~ /(\d*(\.\d*)?)/; $1 } +sub bool2text { $_[0] ? "true" : "false" } +sub bool2yesno { $_[0] ? "yes" : "no" } +sub text2bool { my $t = lc($_[0]); $t eq "true" || $t eq "yes" ? 1 : 0 } + +sub chomp_ { my @l = map { my $l = $_; chomp $l; $l } @_; wantarray ? @l : $l[0] } + +sub backtrace { + my $s; + for (my $i = 1; caller($i); $i++) { + my ($package, $file, $line, $func) = caller($i); + $s .= "$func() called from $file:$line\n"; + } + $s; +} + +1; + |