diff options
Diffstat (limited to 'MDK/Common/Various.pm')
-rw-r--r-- | MDK/Common/Various.pm | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/MDK/Common/Various.pm b/MDK/Common/Various.pm index 93fbb80..a8de5fb 100644 --- a/MDK/Common/Various.pm +++ b/MDK/Common/Various.pm @@ -1,3 +1,82 @@ +=head1 NAME + +MDK::Common::Various - miscellaneous functions + +=head1 SYNOPSIS + + use MDK::Common::Various qw(:all); + +=head1 EXPORTS + +=over + +=item first(LIST) + +returns the first value. C<first(XXX)> is an alternative for C<((XXX)[0])> + +=item second(LIST) + +returns the second value. C<second(XXX)> is an alternative for C<((XXX)[1])> + +=item top(LIST) + +returns the last value. C<top(@l)> is an alternative for C<$l[$#l]> + +=item to_bool(SCALAR) + +returns a value in { 0, 1 } + +=item to_int(STRING) + +extracts the number from the string. You could use directly C<int "11 foo">, but +you'll get I<Argument "11 foo" isn't numeric in int>. It also handles returns +11 for C<"foo 11 bar"> + +=item to_float(STRING) + +extract a decimal number from the string + +=item bool2text(SCALAR) + +returns a value in { "true", "false" } + +=item bool2yesno(SCALAR) + +returns a value in { "yes", "no" } + +=item text2bool(STRING) + +inverse of C<bool2text> and C<bool2yesno> + +=item chomp_(STRING) + +non-mutable version of chomp: do not modify the argument, returns the chomp'ed +value. Also works on lists: C<chomp_($a, $b)> is equivalent to +C<chomp($a) ; chomp($b) ; ($a,$b)> + +=item backtrace() + +returns a string describing the backtrace. eg: + + sub g { print "oops\n", backtrace() } + sub f { &g } + f(); + +gives + + oops + main::g() called from /tmp/t.pl:2 + main::f() called from /tmp/t.pl:4 + +=back + +=head1 SEE ALSO + +L<MDK::Common> + +=cut + + package MDK::Common::Various; use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK); |