blob: 93fbb807e7d6d6d7d3912eac60b4d98301ebbfd6 (
plain)
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
|
package MDK::Common::Various;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(first second top to_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 to_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;
|