Log::Parallel::Sql::Numbers - force values to be numbers


Log-Parallel documentation Contained in the Log-Parallel distribution.

Index


Code Index:

NAME

Top

Log::Parallel::Sql::Numbers - force values to be numbers

SYNOPSIS

Top

 use Log::Parallel::Sql::Numbers;

 $integer = integer($scalar, $default)

 $float = float($scalar, $default)

DESCRIPTION

Top

These simple functions make sure that a scalar is in fact a number. Non-numbers, including nan will be turned into the default.

This is useful if you want to hand an unknown value to a database.

LICENSE

Top

This package may be used and redistributed under the terms of either the Artistic 2.0 or LGPL 2.1 license.


Log-Parallel documentation Contained in the Log-Parallel distribution.

package Log::Parallel::Sql::Numbers;

use strict;
use warnings;
require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw(integer float);

sub integer
{
	my ($n, $default) = @_;
	unless (defined($n) && $n ne 'nan' && $n ne '') {
		return (defined($default) ? $default : -1);
	}
	return int($n);
}

sub float
{
	my ($n, $default) = @_;
	unless (defined($n) && $n ne 'nan' && $n ne '') {
		return (defined($default) ? $default : -9999);
	}
	return 0.0+$n;
}

1;

__END__