Fukurama-Class

 view release on metacpan or  search on metacpan

lib/Fukurama/Class/DataTypes.pm  view on Meta::CPAN

		(0, $_[0] * 1);
	},
	float		=> sub {
		return 1 if(
			defined($_[0])
			&& ( $_[0] =~ m/^[0-9]+\.?[0-9]*$/ || $_[0] =~ m/^[0-9]+\.?[0-9]*e\+?[0-9]+/)
			&& ($_[0] * 1) == $_[0]
			&& !&$HAS_OVERFLOW($_[0])
		);
		return (0, $_[0]) if(!defined($_[0]));
		return (0, $_[0], 'NaN') if($_[0] !~ m/^[0-9]+\.?[0-9]*$/ && $_[0] !~ m/^[0-9]+\.?[0-9]*e\+?[0-9]+$/);
		return (0, $_[0] * 1, 'overflow') if(&$HAS_OVERFLOW($_[0]) || ($_[0] * 1) != $_[0]);
		(0, $_[0]);
	},
	decimal		=> sub {
		return 1 if(defined($_[0]) && $_[0] =~ m/^\-?[0-9]+\.?[0-9]*$/ && ($_[0] * 1) eq $_[0]);
		return (0, $_[0]) if(!defined($_[0]));
		return (0, $_[0], 'NaN') if($_[0] !~ m/^[0-9]+\.?[0-9]*$/ && $_[0] !~ m/^[0-9]+\.?[0-9]*e\+?[0-9]+$/);
		return (0, $_[0] * 1, 'overflow') if(&$HAS_OVERFLOW($_[0]) || ($_[0] * 1) ne $_[0]);
		return (0, $_[0], 'noDec') if($_[0] !~ m/^\-?[0-9]+\.?[0-9]*$/);
		(0, $_[0] * 1);
	},
	class		=> sub {
		return 1 if(!ref($_[0]) && UNIVERSAL::isa($_[0], $_[0]));
		(0, $_[0]);
	},
	object		=> sub {
		return 1 if(ref($_[0]) && UNIVERSAL::isa($_[0], ref($_[0])));

t/DataTypes.t  view on Meta::CPAN

test_type('boolean', 1, undef, 'false', 0, 0);
test_type('boolean', 0, undef, 'undef', 0, undef);
test_type('boolean', 0, undef, '2', 0, 2);

test_type('float', 1, undef, 'int', 0, 1);
test_type('float', 1, undef, 'decimal', 0, 1.1);
test_type('float', 1, undef, 'float', 0, 1.1e15);
test_type('float', 1, undef, 'float as string', 0, '1.1111111111e99');

test_type('float', 0, 'overflow', 'overflow', 0, $overfloating_float);
test_type('float', 0, 'NaN', 'not a number', 0, '1..1111111111e99999');
test_type('float', 0, undef, 'undef', 0, undef);

test_type('decimal', 1, undef, 'int', 0, 78);
test_type('decimal', 1, undef, 'decimal', 0, 1.1);
test_type('decimal', 1, undef, 'negative decimal', 0, -51.1);
test_type('decimal', 0, 'noDec', 'float', 0, $overflowing_int * 1);
test_type('decimal', 0, 'NaN', 'string', 0, '1a1');
test_type('decimal', 0, 'overflow', 'overflow', 0, $overfloating_float);
test_type('decimal', 0, 'NaN', 'not a number', 0, '1..1111111111e99999');
test_type('decimal', 0, undef, 'undef', 0, undef);
test_type('decimal', 0, 'overflow', 'cutted int', 0, ('1.'. ('0' x $overfloat_length) . '5'));

test_type('class', 1, undef, 'classname', 1, 'MyOwnClass');
test_type('class', 0, undef, 'instance', 1, MyOwnClass->new());
test_type('class', 0, undef, 'no classname', 1, 'MyNonexistingClass');
test_type('class', 0, undef, 'undef', 1, undef);

test_type('object', 0, undef, 'classname', 1, 'MyOwnClass');
test_type('object', 1, undef, 'instance', 1, MyOwnClass->new());



( run in 0.396 second using v1.01-cache-2.11-cpan-0d8aa00de5b )