r1844 - in packages: . libdata-types-perl
libdata-types-perl/branches libdata-types-perl/branches/upstream
libdata-types-perl/branches/upstream/current
libdata-types-perl/branches/upstream/current/lib
libdata-types-perl/branches/upstream/current/lib/Data
libdata-types-perl/branches/upstream/current/t
Krzysztof Krzyzaniak
eloy at costa.debian.org
Wed Jan 4 09:19:02 UTC 2006
Author: eloy
Date: 2006-01-04 09:19:01 +0000 (Wed, 04 Jan 2006)
New Revision: 1844
Added:
packages/libdata-types-perl/
packages/libdata-types-perl/branches/
packages/libdata-types-perl/branches/upstream/
packages/libdata-types-perl/branches/upstream/current/
packages/libdata-types-perl/branches/upstream/current/Build.PL
packages/libdata-types-perl/branches/upstream/current/Changes
packages/libdata-types-perl/branches/upstream/current/MANIFEST
packages/libdata-types-perl/branches/upstream/current/META.yml
packages/libdata-types-perl/branches/upstream/current/Makefile.PL
packages/libdata-types-perl/branches/upstream/current/README
packages/libdata-types-perl/branches/upstream/current/lib/
packages/libdata-types-perl/branches/upstream/current/lib/Data/
packages/libdata-types-perl/branches/upstream/current/lib/Data/Types.pm
packages/libdata-types-perl/branches/upstream/current/t/
packages/libdata-types-perl/branches/upstream/current/t/types.t
packages/libdata-types-perl/tags/
Log:
[svn-inject] Installing original source of libdata-types-perl
Added: packages/libdata-types-perl/branches/upstream/current/Build.PL
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/Build.PL 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/Build.PL 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,8 @@
+use Module::Build;
+
+my $build = Module::Build->new
+ ( module_name => 'Data::Types',
+ license => 'perl',
+ create_makefile_pl => 'passthrough',
+ );
+$build->create_build_script;
Added: packages/libdata-types-perl/branches/upstream/current/Changes
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/Changes 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/Changes 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,22 @@
+Revision history for Perl extension Data::Types.
+
+0.05 Tue Aug 26 01:21:03 2003
+ - Switched to Module::Build.
+
+0.04 Thu Jul 25 05:09:13 2002
+ - Added reference to Arthur Bergman's new "types" pragma for Perl
+ 5.8.0. Thought I'd done it in 0.03, but I guess not.
+
+0.03 Mon Jul 22 21:05:26 2002
+ - Fixed to_float() tests so that comparison is more precise. Necessary
+ for compatability with Perl 5.8.0 (and probably better, anyway).
+ - Reorganized structure of distribution to reflect more modern standard
+ for CPAN modules.
+
+0.02 Thu Jan 3 22:06:42 PST 2002
+ - Added second argument to to_string() that will truncate the string.
+ - Fixed Regular expression in is_int() so that it doesn't match '+' or
+ '-'. Thanks to David Alban for the spot.
+
+0.01 Wed Jan 2 12:13:19 PST 2002
+ - original version.
Added: packages/libdata-types-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/MANIFEST 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/MANIFEST 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,8 @@
+Build.PL
+Changes
+MANIFEST This list of files
+META.yml
+Makefile.PL
+README
+lib/Data/Types.pm
+t/types.t
Added: packages/libdata-types-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/META.yml 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/META.yml 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,14 @@
+--- #YAML:1.0
+name: Data-Types
+version: 0.05
+license: perl
+distribution_type: module
+requires: {}
+recommends: {}
+build_requires: {}
+conflicts: {}
+provides:
+ Data::Types:
+ file: lib/Data/Types.pm
+ version: 0.05
+generated_by: Module::Build version 0.19_05
Added: packages/libdata-types-perl/branches/upstream/current/Makefile.PL
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/Makefile.PL 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/Makefile.PL 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,28 @@
+
+ unless (eval "use Module::Build::Compat 0.02; 1" ) {
+ print "This module requires Module::Build to install itself.\n";
+
+ require ExtUtils::MakeMaker;
+ my $yn = ExtUtils::MakeMaker::prompt
+ (' Install Module::Build now from CPAN?', 'y');
+
+ unless ($yn =~ /^y/i) {
+ warn " *** Cannot install without Module::Build. Exiting ...\n";
+ exit 1;
+ }
+
+ require Cwd;
+ require File::Spec;
+ require CPAN;
+
+ # Save this 'cause CPAN will chdir all over the place.
+ my $cwd = Cwd::cwd();
+ my $makefile = File::Spec->rel2abs($0);
+
+ CPAN::Shell->install('Module::Build::Compat');
+
+ chdir $cwd or die "Cannot chdir() back to $cwd: $!";
+ exec $^X, $makefile, @ARGV; # Redo now that we have Module::Build
+ }
+ Module::Build::Compat->run_build_pl(args => \@ARGV);
+ Module::Build::Compat->write_makefile();
Added: packages/libdata-types-perl/branches/upstream/current/README
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/README 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/README 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,34 @@
+Data/Types version 0.05
+=======================
+
+This module exports a number of functions that are useful for validating and
+converting data types. It is intended for use in applications where data types
+are more important than they typically are in Perl -- e.g., for database
+applications.
+
+INSTALLATION
+
+To install this module, type the following:
+
+ perl Build.PL
+ ./Build
+ ./Build test
+ ./Build install
+
+Or, if you don't have Module::Build installed, type the following:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+DEPENDENCIES
+
+This module requires no modules or libraries not already included with Perl.
+
+COPYRIGHT AND LICENCE
+
+Copyright (c) 2002-2003, David Wheeler. All Rights Reserved.
+
+This module is free software; you can redistribute it and/or modify it under the
+same terms as Perl itself.
Added: packages/libdata-types-perl/branches/upstream/current/lib/Data/Types.pm
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/lib/Data/Types.pm 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/lib/Data/Types.pm 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,397 @@
+package Data::Types;
+
+use strict;
+require Exporter;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+
+$VERSION = '0.05';
+
+ at ISA = qw(Exporter);
+
+ at EXPORT_OK = qw(is_whole to_whole is_int to_int is_real to_real is_decimal
+ to_decimal is_float to_float is_string to_string
+);
+
+ at EXPORT = qw();
+
+%EXPORT_TAGS = ( all => \@EXPORT_OK,
+ whole => [qw(is_whole to_whole)],
+ int => [qw(is_int to_int)],
+ decimal => [qw(is_decimal to_decimal)],
+ real => [qw(is_real to_real)],
+ float => [qw(is_float to_float)],
+ string => [qw(is_string to_string)],
+ is => [qw(is_whole is_int is_real is_decimal is_float
+ is_string)],
+ to => [qw(to_whole to_int to_real to_decimal to_float
+ to_string)]
+);
+
+use constant DEF_PRECISION => 5;
+
+################################################################################
+# FUNCTIONS #
+################################################################################
+
+sub is_whole ($) {
+ return unless $_[0];
+ return unless $_[0] =~ /^\d+$/;
+ return 1;
+}
+
+sub to_whole ($) {
+ return unless $_[0];
+ my ($num) = $_[0] =~ /([+-]?(?:\d+(?:\.\d*)?|\.\d+))/;
+ return unless $num && $num > .5;
+ sprintf "%.0f", $num;
+}
+
+sub is_int ($) {
+ return unless defined $_[0] && $_[0] ne '';
+ return unless $_[0] =~ /^[+-]?\d+$/;
+ return 1;
+}
+
+sub to_int ($) {
+ return unless defined $_[0] && $_[0] ne '';
+ my ($num) = $_[0] =~ /([+-]?(?:\d+(?:\.\d*)?|\.\d+))/;
+ return unless defined $num;
+ sprintf "%.0f", $num;
+}
+
+sub is_decimal ($) {
+ return unless defined $_[0] && $_[0] ne '';
+ return unless $_[0] =~ /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/;
+ return 1;
+}
+
+sub to_decimal ($;$) {
+ return unless defined $_[0] && $_[0] ne '';
+ my ($num) = $_[0] =~ /([+-]?(?:\d+(?:\.\d*)?|\.\d+))/;
+ return unless defined $num;
+ $_[1] ||= DEF_PRECISION;
+ sprintf "%.$_[1]f", $num;
+}
+
+#sub is_real ($) {
+# return unless defined $_[0] && $_[0] ne '';
+# return unless $_[0] =~ /^[+-]?\d*\.?\d*$/;
+# return 1;
+#}
+
+#sub to_real ($) {
+# return unless defined $_[0] && $_[0] ne '';
+# sprintf "%f", $_[0] =~ /([+-]?\d*\.?\d*)/;
+#}
+
+# These may need to be separated in the future, in order to identify non-decimal
+# real numbers.
+*is_real = *is_decimal;
+*to_real = *to_decimal;
+
+sub is_float ($) {
+ return unless defined $_[0] && $_[0] ne '';
+ return unless $_[0] =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/;
+ return 1;
+}
+
+sub to_float ($;$) {
+ return unless defined $_[0] && $_[0] ne '';
+ my ($num) = $_[0] =~ /(([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?)/;
+ return unless defined $num;
+ my $type = $num =~ /e|E/ ? 'e' : 'f';
+ $_[1] ||= DEF_PRECISION;
+ sprintf "%.$_[1]$type", $num;
+# sprintf "%g", $_[0] =~ /(([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?)/;
+}
+
+sub is_string ($) { defined $_[0] && ! ref $_[0] }
+
+sub to_string ($;$) {
+ return unless defined $_[0];
+ return $_[1] ? substr("$_[0]", 0, $_[1]) : "$_[0]";
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Data::Types - Validate and convert data types.
+
+=head1 SYNOPSIS
+
+ use Data::Types qw(:all);
+
+ my $whole = 4.5;
+ $whole = to_whole($whole) unless is_whole($whole);
+
+ my $int = 1.2;
+ $int = to_int($int) unless is_int($int);
+
+ my $decimal = '1.2foo';
+ $decimal = to_decimal($decimal) unless is_decimal($decimal);
+
+ my $real = '1.2foo';
+ $real = to_real($real) unless is_real($real);
+
+ my $float = '1.2foo';
+ $float = to_float($float) unless is_float($float);
+
+ my $string = [];
+ $string = to_string($string) unless is_string($string);
+
+=head1 DESCRIPTION
+
+This module exports a number of functions that are useful for validating and
+converting data types. It is intended for use in applications where data types
+are more important than they typically are in Perl -- e.g., database
+applications.
+
+=head1 EXPORT
+
+No functions are exported by default, though each function may be exported
+explicitly (see L<"Functions">, below, for a list of functions available for
+export). The following export tags are supported:
+
+=over 4
+
+=item :whole
+
+Exports is_whole() and to_whole().
+
+=item :int
+
+Exports is_int() and to_int().
+
+=item :decimal
+
+Exports is_decimal() and to_decimal().
+
+=item :real
+
+Exports is_real() and to_real().
+
+=item :float
+
+Exports is_float() and to_float().
+
+=item :string
+
+Exports is_string() and to_string().
+
+=item :is
+
+Exports all validation functions: is_whole(), is_int(), is_real(), is_decimal(),
+is_float(), and is_string().
+
+=item :to
+
+Exports all conversion functions: to_whole(), to_int(), to_real(), to_decimal(),
+to_float(), and to_string().
+
+=item :all
+
+Exports all functions.
+
+=back
+
+=head1 FUNCTIONS
+
+=head2 is_whole
+
+ my $bool = is_whole($val);
+
+Returns true if $val is a whole number (exclusive of 0), and false if it is not.
+The regular expression used to test the wholeness of $val is C</^\d+$/>.
+
+ my $bool = is_whole(1); # Returns true.
+ $bool = is_whole(-1); # Returns false.
+ $bool = is_whole(0); # Returns false.
+
+=head2 to_whole
+
+ my $whole = to_whole($val);
+
+Converts $val to a whole number and returns it. Numbers will be rounded to the
+nearest whole. Note that since 0 (zero) is not considered a whole number by this
+module, it will not be returned. If $val is a mixture of numbers and letters,
+to_whole() will extract the first decimal number it finds and convert that
+number to a whole number.
+
+ my $whole = to_whole(10); # Returns 10.
+ $whole = to_whole(0); # Returns undef.
+ $whole = to_whole(.22); # Returns undef (rounded down to 0).
+ $whole = to_whole(-2); # Returns undef.
+ $whole = to_whole('foo3.56'); # Returns 4.
+ $whole = to_whole('foo'); # Returns undef.
+
+=head2 is_int
+
+ my $bool = is_int($val);
+
+Returns true if $val is an integer, and false if it is not. Numbers may be
+preceded by a plus or minus sign. The regular expression used to test for an
+integer in $val is C</^[+-]?\d+$/>.
+
+ my $bool = is_int(0); # Returns true.
+ $bool = is_int(22); # Returns true.
+ $bool = is_int(-22); # Returns false.
+ $bool = is_int(3.2); # Returns false.
+
+=head2 to_int
+
+ my $int = to_int($val);
+
+Converts $val to an integer. If $val is a decimal number, it will be rounded to
+the nearest integer. If $val is a mixture of numbers and letters, to_int() will
+extract the first decimal number it finds and convert that number to an integer.
+
+ my $int = to_int(10.5); # Returns 10.
+ $int = to_int(10.51); # Returns 11.
+ $int = to_int(-0.22); # Returns 0.
+ $int = to_int(-6.51); # Returns 7.
+ $int = to_int('foo'); # Returns undef.
+
+=head2 is_decimal
+
+ my $bool = is_decimal($val);
+
+Returns true if $val is a decimal number, and false if it is not. Numbers may be
+preceded by a plus or minus sign. The regular expression used to test $val is
+C</^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/>.
+
+ my $bool = is_decimal(10) # Returns true.
+ $bool = is_decimal(10.8) # Returns true.
+ $bool = is_decimal(-33.48) # Returns true.
+ $bool = is_decimal((1.23e99) # Returns false.
+
+=head2 to_decimal
+
+ my $dec = to_decimal($val);
+ $dec = to_decimal($val, $precision);
+
+Converts $val to a decimal number. The optional second argument sets the
+precision of the number. The default precision is 5. If $val is a mixture of
+numbers and letters, to_decimal() will extract the first decimal number it
+finds.
+
+ my $dec = to_decimal(0); # Returns 0.00000.
+ $dec = to_decimal(10.5); # Returns 10.5.
+ $dec = to_decimal(10.500009); # Returns 10.50001.
+ $dec = to_decimal(10.500009, 7); # Returns 10.5000090.
+ $dec = to_decimal('foo10.3') # Returns 10.30000.
+ $dec = to_decimal('foo-4.9') # Returns -4.90000.
+ $dec = to_decimal('foo') # Returns undef.
+
+=head2 is_real
+
+ my $bool = is_real($val);
+
+Returns true if $val is a real number, and false if it is not.
+
+B<Note:> This function is currently equivalent to is_decimal(), since this
+module cannot identify non-decimal real numbers (e.g., irrational numbers). This
+implementation may change in the future.
+
+=head2 to_real
+
+ my $real = to_real($val);
+ $real = to_real($val, $precision);
+
+Converts $val to a real number.
+
+B<Note:> Currently, this function is the equivalent of to_decimal(), since this
+module cannot identify non-decimal real numbers (e.g., irrational numbers). This
+implementation may change in the future.
+
+=head2 is_float
+
+ my $bool = is_real($val);
+
+Returns true if $val is a float, and false if it is not. The regular expression
+used to test $val is C</^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/>.
+
+ my $bool = is_real(30); # Returns true.
+ $bool = is_real(1.23e99); # Returns true.
+ $bool = is_real('foo'); # Returns false.
+
+=head2 to_float
+
+ my $dec = to_float($val);
+ $dec = to_float($val, $precision);
+
+Converts $val to a float. The optional second argument sets the precision of the
+number. The default precision is 5. If $val is a mixture of numbers and letters,
+to_float() will extract the first float it finds.
+
+ my $float = to_float(1.23); # Returns 1.23000.
+ $float = to_float(1.23e99); # Returns 1.23000e+99.
+ $float = to_float(1.23e99, 1); # Returns 1.2e+99.
+ $float = to_float('foo-1.23'); # Returns -1.23000.
+ $float = to_float('ick_1.23e99foo'); # Returns 1.23000e+99.
+
+=head2 is_string
+
+ my $bool = is_string($val);
+
+Returns true if $val is a string, and false if it is not. All defined
+non-references are considered strings.
+
+ my $bool = is_string('foo'); # Returns true.
+ $bool = is_string(20001); # Returns true.
+ $bool = is_string([]); # Returns false.
+ $bool = is_string(undef); # Returns false.
+
+=head2 to_string
+
+ my $string = to_string($val);
+ $string = to_string($val, $length);
+
+Converts $val into a string. If $val is a reference, the string value of the
+reference will be returned. Such a value may be a memory address, or some other
+value, if the stringification operator has been overridden for the object stored
+in $val. If the optional second argument $length is passed, to_string() will
+truncate the string to that length. If $length is 0 (zero), it will not limit
+the length of the return string. If $val is undefined, to_string() will return
+undef.
+
+ my $string = to_string('foo'); # Returns 'foo'.
+ $string = to_string([]); # Returns 'ARRAY(0x101bec14)'.
+ $string = to_string(undef); # Returns undef.
+ $string = to_string('hello', 4); # Returns 'hell'.
+
+=head1 BUGS
+
+Hopefully none. Contact the author if you discover any.
+
+=head1 AUTHOR
+
+David Wheeler <david at wheeler.net>
+
+=head1 SEE ALSO
+
+L<perlfaq4|perlfaq4/"How do I determine whether a scalar is anumber/whole/integer/float?">
+lists the most of the regular expressions used to identify the different numeric
+types used in this module.
+
+L<String::Checker|String::Checker> also does some data type validation.
+
+L<String::Scanf|String::Scanf> reimplements the C C<sscanf()> function in
+perl, and also does data type validation and conversion.
+
+L<Regexp::Common|Regexp::Common> contains many useful common regular expressions
+(surprise!), including some that can be used to identify data types.
+
+Arthur Bergman's L<types|types> pragma, offers compile-time data types for
+Perl 5.8.0. The data types include int, float, and string. I highly recommend
+using this prgrma for fast, static data types.
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2002-2003, David Wheeler. All Rights Reserved.
+
+This module is free software; you can redistribute it and/or modify it under the
+same terms as Perl itself.
+
+=cut
Added: packages/libdata-types-perl/branches/upstream/current/t/types.t
===================================================================
--- packages/libdata-types-perl/branches/upstream/current/t/types.t 2006-01-03 16:56:06 UTC (rev 1843)
+++ packages/libdata-types-perl/branches/upstream/current/t/types.t 2006-01-04 09:19:01 UTC (rev 1844)
@@ -0,0 +1,180 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test;
+BEGIN { plan tests => 145 };
+use Data::Types qw(:all);
+ok(1); # If we made it this far, we're ok.
+
+#########################
+
+# Test is_whole.
+ok( is_whole(10) );
+ok( is_whole(22) );
+ok( is_whole(1) );
+ok( is_whole(700) );
+ok( ! is_whole(0) );
+ok( ! is_whole(.22) );
+ok( ! is_whole(-33) );
+ok( ! is_whole(-0.1) );
+
+# Test to_whole.
+ok( to_whole(10) == 10 );
+ok( to_whole(1) == 1 );
+ok( to_whole('foo33') == 33);
+ok( to_whole('ri+4') == 4 );
+ok( to_whole('+45ts') == 45 );
+ok( to_whole(1.23e99) == 1) ; # This should probably be changed somehow.
+ok( ! defined to_whole(0) );
+ok( ! defined to_whole('blech') );
+ok( ! defined to_whole('') );
+ok( ! defined to_whole(undef) );
+ok( ! defined to_whole('foo00') );
+ok( ! defined to_whole(.44) );
+ok( ! defined to_whole('foo-33') );
+ok( ! defined to_whole(-44) );
+ok( ! defined to_whole(-0.33) );
+ok( ! defined to_whole('sep-0.1') );
+
+# Test is_int.
+ok( is_int(10) );
+ok( is_int(0) );
+ok( is_int(-33) );
+ok( is_int(+23) );
+ok( ! is_int('+') );
+ok( ! is_int('-') );
+ok( ! is_int(22.2) );
+ok( ! is_int(0.44) );
+ok( ! is_int('foo') );
+ok( ! is_int('33foo') );
+ok( ! is_int(-33.2) );
+ok( ! is_int(undef));
+ok( ! is_int(''));
+
+# Test to_int.
+ok( to_int(10) == 10 );
+ok( to_int(10.22) == 10 );
+ok( to_int(0.44) == 0 );
+ok( to_int(0.54) == 1 );
+ok( to_int(10.468473895043) == 10 );
+ok( to_int(+10.51) == 11);
+ok( to_int("10.44foo") == 10 );
+ok( to_int(-22) == -22 );
+ok( to_int(-22.6) == -23);
+ok( to_int(1.23e99) == 1) ; # This should probably be changed somehow.
+ok( ! defined to_int(undef) );
+ok( ! defined to_int('') );
+ok( ! defined to_int('foo') );
+
+# Test is_decimal.
+ok( is_decimal(.22) );
+ok( is_decimal(0.4) );
+ok( is_decimal(22.44) );
+ok( is_decimal(-0.44) );
+ok( is_decimal(-100.45) );
+ok( is_decimal(0) );
+ok( is_decimal(22) );
+ok( is_decimal(-33) );
+ok( is_decimal(-33.0) );
+ok( ! is_decimal('+') );
+ok( ! is_decimal('-') );
+ok( ! is_decimal(undef) );
+ok( ! is_decimal('foo') );
+ok( ! is_decimal('foo22') );
+ok( ! is_decimal('22foo') );
+ok( ! is_decimal(1.23e99) );
+
+# Test to_decimal.
+ok( to_decimal(0) == 0 );
+ok( to_decimal(100) == 100 );
+ok( to_decimal(0.22) == 0.22 );
+ok( to_decimal(-4) == -4 );
+ok( to_decimal(-3.4) == -3.4 );
+ok( to_decimal('foo3.5') == 3.5 );
+ok( to_decimal('-35foo') == -35 );
+ok( to_decimal('foo-3') == -3 );
+ok( to_decimal('40foo') == 40 );
+ok( to_decimal(1.23e99) == 1.23 ); # This should probably be changed somehow.
+ok( to_decimal(10.500009) == 10.50001 );
+ok( to_decimal(10.500009, 10) == 10.500009 );
+ok( ! defined to_decimal(undef) );
+ok( ! defined to_decimal('') );
+ok( ! defined to_decimal('foo'));
+
+# Test is_real.
+ok( is_real(0) );
+ok( is_real(100) );
+ok( is_real(0.22) );
+ok( is_real(-4) );
+ok( is_real(-4.9) );
+ok( is_real(12043.3423) );
+ok( ! is_real('foo') );
+ok( ! is_real('+') );
+ok( ! is_real('-') );
+ok( ! is_real(undef) );
+ok( ! is_real('foo34.33') );
+ok( ! is_real(1.23e99) );
+
+# Test to_real.
+ok( to_real(0) == 0 );
+ok( to_real(100) == 100 );
+ok( to_real(0.22) == 0.22 );
+ok( to_real(-4) == -4 );
+ok( to_real(-3.4) == -3.4 );
+ok( to_real('foo3.5') == 3.5 );
+ok( to_real('-35foo') == -35 );
+ok( to_real('foo-3') == -3 );
+ok( to_real('40foo') == 40 );
+ok( to_real(1.23e99) == 1.23 ); # This should probably be changed somehow.
+ok( ! defined to_real(undef) );
+ok( ! defined to_real('') );
+ok( ! defined to_real('foo'));
+
+# Test is_float.
+ok( is_float(10) );
+ok( is_float(11.2) );
+ok( is_float(0.2) );
+ok( is_float(345.96948383) );
+ok( is_float(1.23e99) );
+ok( is_float(-938.54) );
+ok( is_float(+234.5) );
+ok( !is_float('foo') );
+ok( !is_float('22.34foo') );
+ok( !is_float(undef) );
+ok( !is_float('+') );
+ok( !is_float('-') );
+ok( !is_float('') );
+
+# Test to_float.
+ok( to_float(10) == 10 );
+ok( to_float(11.2) == 11.2 );
+ok( to_float(456.98765) == 456.98765 );
+ok( to_float(0) == 0 );
+ok( to_float('44.334foo') == 44.334 );
+ok( to_float(-34.3) == -34.3 );
+ok( to_float(+456.04) == 456.04 );
+ok( to_float(1.23e99) == 1.23000e99 );
+ok( to_float(1.23e99, 1) == 1.2e99 );
+ok( to_float('foo1.23e99') == 1.23000e99 );
+ok( ! defined to_float(undef) );
+ok( ! defined to_float('') );
+ok( ! defined to_float('foo'));
+
+# Test is_string.
+ok( is_string('foo') );
+ok( is_string(4) );
+my $var = [];
+ok( is_string("$var") );
+ok( ! is_string($var) );
+ok( ! is_string(undef) );
+
+# Test is_string.
+ok( to_string(44) eq '44' );
+ok( to_string('foo') eq 'foo' );
+ok( to_string('') eq '' );
+ok( to_string(0) eq '0' );
+ok( to_string($var) eq "$var" );
+ok( ! defined to_string(undef) );
+ok( to_string('hello', 4) eq 'hell' );
+
+__END__
More information about the Pkg-perl-cvs-commits
mailing list