Data-Util

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


0.43 Sun Dec 14 13:37:43 2008
    - fix modifer's order of modify_subroutine()/subroutine_modifier()
        to be compatible with Moose
    - fix some bugs on neat()/is_number()/install_subroutine()
    - remove "original" property from subroutine_modifier(), which seems
        a waste of memory
    - internal cleanup

0.42 Wed Dec 10 13:42:50 2008
    - fix is_number()/is_integer() to refuse Infinity and NaN correctly
    - fix a possible segfault on install_subrouitne()
    - internal cleanup

0.41 Man Dec  8 11:36:38 2008
    - change get_stash() to be able to take an object reference
    - change is_number()/is_integer() to refuse "0 but true"
    - fix some bugs

0.40 Sun Dec  7 13:42:17 2008
    - add is_value()/is_string()/is_number()/is_integer() functions

lib/Data/Util/JA.pod  view on Meta::CPAN

この関数には検証を行う対応関数がありません。

=item is_number(value)

I<value>が数値かどうかをチェックします。
ここでB<数値>とは,数値コンテキスト(たとえばC<< sprintf '%g', $value >>)
で警告を出さずに数値に変換可能であり,
かつPerlプログラム中にリテラルとしておくことができる値という意味です。

すなわち,この関数はC<Scalar::Util::looks_like_number()>と異なり,
C<Infinity>やC<NaN>はリテラルとしてプログラム中に置くことはできないため,
数値として扱いません。また,数値化したときに警告を出さない例外である
C<"0 but true">も同じ理由で数値として扱いません。

この関数には検証を行う対応関数がありません。

=item is_integer(value)

I<value>が整数かどうかをチェックします。これはC<is_number()>の判定に加えて,
整数値かどうかをチェックします。

t/10_neat.t  view on Meta::CPAN

is neat(*ok), '*main::ok';
ok neat({'!foo' => '!bar'});
unlike neat({foo => 'bar', baz => 'bax'}), qr/undef/;
like neat(\&foo), qr/^\\&main::foo\(.*\)$/;
like neat(Foo->new(42)), qr/^Foo=HASH\(.+\)$/, 'for an overloaded object';

like neat(qr/foo/), qr/foo/, 'neat(qr/foo/) includes "foo"';

ok neat(+9**9**9), '+Inf';
ok neat(-9**9**9), '-Inf';
ok neat(9**9**9 - 9**9**9), 'NaN';

tie my $s, 'Tie::StdScalar', "foo";
is neat($s), q{"foo"}, 'for magical scalar';

my $x;

$x = tie my @a, 'Tie::StdArray';
$x->[0] = 42;

is neat($a[0]), 42, 'for magical scalar (aelem)';

t/18_is_value.t  view on Meta::CPAN

	ok is_integer($x), sprintf 'is_integer(%s)', neat($x);

	my $w;
	local $SIG{__WARN__} = sub{ $w = "@_" };
	my $i = 0+$x;

	is $w, undef, 'numify-safe';
}
tie $s, 'Tie::StdScalar', 'magic';
foreach my $x(
		undef, 3.14, '0.0', 'foo', (9**9**9), -(9**9**9), 'NaN',
		INF(), -INF(), NAN(), -NAN(), 1 != 1,
	*ok, [42], *STDIN{IO}, '0 but true', $s){

	ok !is_integer($x), sprintf '!is_integer(%s)', neat($x);
}

tie $s, 'Tie::StdScalar', 123.456;
foreach my $x(0, 1, -1, 3.14, '0', '+0', '-0', '0E0', ' 0.0', '1e-1', 2**32+0.1, $s){
	ok is_number($x), sprintf 'is_number(%s)', neat($x);

	my $w;
	local $SIG{__WARN__} = sub{ $w = "@_" };
	my $n = 0+$x;

	is $w, undef, 'numify-safe';
}

tie $s, 'Tie::StdScalar', 'magic';
foreach my $x(undef, 'foo', 'Inf', '-Infinity', 'NaN',
		INF(), -INF(), NAN(), -NAN(), 1 != 1,
		'0 but true', *ok, [42], *STDIN{IO}, $s){

	ok !is_number($x), sprintf '!is_number(%s)', neat($x);
}

xs-src/misc_scalar.c  view on Meta::CPAN

		else{
			NV const nv = SvNV(x);

			if(nv == NV_INF){
				sv_catpvs(dsv, "+Inf");
			}
			else if(nv == -NV_INF){
				sv_catpvs(dsv, "-Inf");
			}
			else if(Perl_isnan(nv)){
				sv_catpvs(dsv, "NaN");
			}
			else{
				Perl_sv_catpvf(aTHX_ dsv, "%"NVgf, nv);
			}
		}
	}
	else{
		sv_catpvs(dsv, "undef");
	}
}



( run in 0.741 second using v1.01-cache-2.11-cpan-4d50c553e7e )