r6446 - in /branches/upstream/libparams-classify-perl/current: Changes MANIFEST META.yml Makefile.PL README lib/Params/Classify.pm t/purity.t

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Fri Aug 10 13:51:45 UTC 2007


Author: gregoa-guest
Date: Fri Aug 10 13:51:45 2007
New Revision: 6446

URL: http://svn.debian.org/wsvn/?sc=1&rev=6446
Log:
[svn-upgrade] Integrating new upstream version, libparams-classify-perl (0.002)

Added:
    branches/upstream/libparams-classify-perl/current/t/purity.t
Modified:
    branches/upstream/libparams-classify-perl/current/Changes
    branches/upstream/libparams-classify-perl/current/MANIFEST
    branches/upstream/libparams-classify-perl/current/META.yml
    branches/upstream/libparams-classify-perl/current/Makefile.PL
    branches/upstream/libparams-classify-perl/current/README
    branches/upstream/libparams-classify-perl/current/lib/Params/Classify.pm

Modified: branches/upstream/libparams-classify-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libparams-classify-perl/current/Changes?rev=6446&op=diff
==============================================================================
--- branches/upstream/libparams-classify-perl/current/Changes (original)
+++ branches/upstream/libparams-classify-perl/current/Changes Fri Aug 10 13:51:45 2007
@@ -1,3 +1,14 @@
+version 0.002; 2007-01-25
+
+  * add is_pure_string() and is_pure_number() functions that determine
+    how complicated a string scalar is
+
+  * in documentation for is_number(), reference Scalar::Number and
+    Data::Integer
+
+  * correct version requirement of Scalar::Util in module, making it
+    consistent with the dependency listed in Makefile.PL
+
 version 0.001; 2006-08-03
 
   * bugfix: in is_number(), check whether numeric conversion warns, rather

Modified: branches/upstream/libparams-classify-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libparams-classify-perl/current/MANIFEST?rev=6446&op=diff
==============================================================================
--- branches/upstream/libparams-classify-perl/current/MANIFEST (original)
+++ branches/upstream/libparams-classify-perl/current/MANIFEST Fri Aug 10 13:51:45 2007
@@ -7,4 +7,5 @@
 lib/Params/Classify.pm
 t/blessed.t
 t/classify.t
+t/purity.t
 t/ref.t

Modified: branches/upstream/libparams-classify-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libparams-classify-perl/current/META.yml?rev=6446&op=diff
==============================================================================
--- branches/upstream/libparams-classify-perl/current/META.yml (original)
+++ branches/upstream/libparams-classify-perl/current/META.yml Fri Aug 10 13:51:45 2007
@@ -1,11 +1,12 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         Params-Classify
-version:      0.001
+version:      0.002
 version_from: lib/Params/Classify.pm
 installdirs:  site
 requires:
+    Scalar::Number:                0.000
     Scalar::Util:                  1.01
 
 distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.30
+generated_by: ExtUtils::MakeMaker version 6.17

Modified: branches/upstream/libparams-classify-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libparams-classify-perl/current/Makefile.PL?rev=6446&op=diff
==============================================================================
--- branches/upstream/libparams-classify-perl/current/Makefile.PL (original)
+++ branches/upstream/libparams-classify-perl/current/Makefile.PL Fri Aug 10 13:51:45 2007
@@ -4,6 +4,7 @@
 	NAME => "Params::Classify",
 	VERSION_FROM => "lib/Params/Classify.pm",
 	PREREQ_PM => {
-		"Scalar::Util" => "1.01",
+		Scalar::Number => "0.000",
+		Scalar::Util => "1.01",
 	},
 );

Modified: branches/upstream/libparams-classify-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libparams-classify-perl/current/README?rev=6446&op=diff
==============================================================================
--- branches/upstream/libparams-classify-perl/current/README (original)
+++ branches/upstream/libparams-classify-perl/current/README Fri Aug 10 13:51:45 2007
@@ -28,7 +28,7 @@
 
 COPYRIGHT
 
-Copyright (C) 2004, 2006 Andrew Main (Zefram) <zefram at fysh.org>
+Copyright (C) 2004, 2006, 2007 Andrew Main (Zefram) <zefram at fysh.org>
 
 This module is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

Modified: branches/upstream/libparams-classify-perl/current/lib/Params/Classify.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libparams-classify-perl/current/lib/Params/Classify.pm?rev=6446&op=diff
==============================================================================
--- branches/upstream/libparams-classify-perl/current/lib/Params/Classify.pm (original)
+++ branches/upstream/libparams-classify-perl/current/lib/Params/Classify.pm Fri Aug 10 13:51:45 2007
@@ -6,7 +6,7 @@
 
 	use Params::Classify qw(scalar_class
 		is_undef
-		is_string is_number
+		is_string is_number is_pure_string is_pure_number
 		is_glob
 		is_ref ref_type
 		is_blessed blessed_class
@@ -18,6 +18,8 @@
 
 	$ok = is_string($foo);
 	$ok = is_number($foo);
+	$ok = is_pure_string($foo);
+	$ok = is_pure_number($foo);
 
 	$ok = is_glob($foo);
 
@@ -52,16 +54,16 @@
 use strict;
 
 use Exporter;
-use Scalar::Util 1.10 qw(blessed reftype);
-
-our $VERSION = "0.001";
+use Scalar::Util 1.01 qw(blessed reftype);
+
+our $VERSION = "0.002";
 
 our @ISA = qw(Exporter);
 
 our @EXPORT_OK = qw(
 	scalar_class
 	is_undef
-	is_string is_number
+	is_string is_number is_pure_string is_pure_number
 	is_glob
 	is_ref ref_type
 	is_blessed blessed_class is_strictly_blessed is_able
@@ -180,19 +182,22 @@
 Note that simple (C<is_string>-satisfying) scalars may have independent
 numeric and string values, despite the usual pretence that they have
 only one value.  Such a scalar is deemed to be a number if I<either> it
-already has a numeric value (e.g., was generated by a numeric literal or
-an arithmetic computation) I<or> its string value has acceptable syntax
-for a number (so it can be converted).  Where a scalar has separate
-numeric and string values (see L<Scalar::Util/dualvar>), it is possible
-for it to have an acceptable numeric value while its string value does
-I<not> have acceptable numeric syntax.  Be careful to use such a value
-only in a numeric context, if you are using it as a number.  C<0+ARG>
-is sufficient to collapse it to an ordinary number if you want the
-numeric value in string form.
-
-A number may be either a native integer or a native floating point value.
-There are several subtypes of floating point value.  For classification
-among floating point values see L<Data::Float>.
+already has a numeric value (e.g., was generated by a numeric literal
+or an arithmetic computation) I<or> its string value has acceptable
+syntax for a number (so it can be converted).  Where a scalar has
+separate numeric and string values (see L<Scalar::Util/dualvar>), it is
+possible for it to have an acceptable numeric value while its string
+value does I<not> have acceptable numeric syntax.  Be careful to use
+such a value only in a numeric context, if you are using it as a number.
+C<scalar_num_part> in L<Scalar::Number> extracts the numeric part of a
+scalar as an ordinary number.  (C<0+ARG> suffices for that unless you
+need to preserve floating point signed zeroes.)
+
+A number may be either a native integer or a native floating point
+value, and there are several subtypes of floating point value.
+For classification, and other handling of numbers in scalars, see
+L<Scalar::Number>.  For details of the two numeric data types, see
+L<Data::Integer> and L<Data::Float>.
 
 This function differs from C<looks_like_number> (see
 L<Scalar::Util/looks_like_number>; also L<perlapi/looks_like_number>
@@ -215,6 +220,42 @@
 	local $SIG{__WARN__} = sub { $warned = 1; };
 	{ no warnings "void"; 0 + $arg; }
 	return !$warned;
+}
+
+=item is_pure_string(ARG)
+
+This returns true iff ARG is defined and an ordinary scalar (i.e.,
+satisfies C<is_string> above) and is fully described by its string value.
+That is, its numeric value is that which would be obtained by automatic
+conversion from the string value.  Such a scalar could have originated
+as a string literal or constructed string.  This excludes many floating
+point number values which stringify lossily.
+
+=cut
+
+sub is_pure_string($) {
+	my($val) = @_;
+	return 0 unless is_string($val);
+	require Scalar::Number;
+	local $SIG{__WARN__} = sub { };
+	return Scalar::Number::sclnum_id_cmp("$val", $val) == 0;
+}
+
+=item is_pure_number(ARG)
+
+This returns true iff ARG is defined and an ordinary scalar (i.e.,
+satisfies C<is_string> above) and is fully described by its numeric value.
+That is, its string value is that which would be obtained by automatic
+conversion from the numeric value.  Such a scalar could have originated
+as a numeric literal or calculated number.  This excludes most strings.
+
+=cut
+
+sub is_pure_number($) {
+	my($val) = @_;
+	return 0 unless is_string($val);
+	require Scalar::Number;
+	return Scalar::Number::scalar_num_part($val) eq $val;
 }
 
 =back
@@ -394,7 +435,9 @@
 =head1 SEE ALSO
 
 L<Data::Float>,
+L<Data::Integer>,
 L<Params::Validate>,
+L<Scalar::Number>,
 L<Scalar::Util>
 
 =head1 AUTHOR
@@ -403,7 +446,7 @@
 
 =head1 COPYRIGHT
 
-Copyright (C) 2004, 2006 Andrew Main (Zefram) <zefram at fysh.org>
+Copyright (C) 2004, 2006, 2007 Andrew Main (Zefram) <zefram at fysh.org>
 
 This module is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

Added: branches/upstream/libparams-classify-perl/current/t/purity.t
URL: http://svn.debian.org/wsvn/branches/upstream/libparams-classify-perl/current/t/purity.t?rev=6446&op=file
==============================================================================
--- branches/upstream/libparams-classify-perl/current/t/purity.t (added)
+++ branches/upstream/libparams-classify-perl/current/t/purity.t Fri Aug 10 13:51:45 2007
@@ -1,0 +1,48 @@
+use Test::More tests => 44;
+
+BEGIN { use_ok "Params::Classify", qw(is_pure_string is_pure_number); }
+
+sub test($$$) {
+	my($expect_str, $expect_num, $val) = @_;
+	is !!is_pure_string($val), !!$expect_str;
+	is !!is_pure_number($val), !!$expect_num;
+}
+
+test 0, 0, undef;
+test 0, 0, *STDOUT;
+test 0, 0, {};
+test 1, 0, "";
+test 1, 1, "0";
+test 1, 1, "1";
+test 1, 0, "1a";
+test 1, 1, "-1";
+test 1, 1, "123";
+test 1, 0, "0123";
+test 1, 0, "a";
+test 1, 0, "0 but true";
+test 1, 0, "00";
+test 1, 1, "1.25";
+test 1, 1, 1.25;
+test 0, 1, 1/3;
+$! = 3; test 0, 0, $!;
+
+SKIP: {
+	eval { require Scalar::Util };
+	skip "dualvar() not available", 4 if $@ ne "";
+	test 1, 1, Scalar::Util::dualvar(123.0, "123");
+	test 0, 0, Scalar::Util::dualvar(3, "xyz");
+}
+
+SKIP: {
+	skip "floating point zero is unsigned", 5
+		unless sprintf("%+.f", -0.0) eq "-0";
+	ok is_pure_number(0);
+	ok is_pure_number(+0.0);
+	ok is_pure_number(-0.0);
+	SKIP: {
+		eval { require Scalar::Util };
+		skip "dualvar() not available", 2 if $@ ne "";
+		ok !is_pure_string(Scalar::Util::dualvar(+0.0, "0"));
+		ok !is_pure_string(Scalar::Util::dualvar(-0.0, "0"));
+	}
+}




More information about the Pkg-perl-cvs-commits mailing list