Skip to content

Edge cases of weird-looking interger-ish strings. #104

Open
@gugod

Description

@gugod

This is related to #103, but a bit more cases. Considering the following test program, running with perl 5.28.1, Mouse v2.5.9. The test program take each strings from @ARGV as $x, and "wash" it with "int($x)" -- which leaves some side-effect inside $x. Then see if it passes Int type constraint.

# x.pl
use v5.18;
use warnings;
use Mouse::Util::TypeConstraints;

my $Int = find_type_constraint 'Int';

for my $x (@ARGV) {
    { no warnings; int($x); };

    if ($Int->check($x)) {
        say " Int\t$x";
    } else {
        say "!Int\t$x";
    }
}

Here's the output when using Mouse::XS

> perl x.pl 1 '-1' '-0' ' 1 ' '  -1 ' 0 00 010 18446744073709551615 1.0 0.1 1.2.3 0.0 0.1.0 0b00 0e 0e0 0e1 1e0 '0 but true' '1 foobar'

 Int	1
 Int	-1
 Int	-0
 Int	 1
 Int	  -1
 Int	0
 Int	00
 Int	010
 Int	18446744073709551615
!Int	1.0
!Int	0.1
!Int	1.2.3
!Int	0.0
!Int	0.1.0
!Int	0b00
!Int	0e
!Int	0e0
!Int	0e1
!Int	1e0
 Int	0 but true
!Int	1 foobar

The output when using Mouse::PurePerl

> MOUSE_PUREPERL=1 perl x.pl 1 '-1' '-0' ' 1 ' '  -1 ' 0 00 010 18446744073709551615 1.0 0.1 1.2.3 0.0 0.1.0 0b00 0e 0e0 0e1 1e0 '0 but true' '1 foobar'

 Int	1
 Int	-1
 Int	-0
!Int	 1
!Int	  -1
 Int	0
 Int	00
 Int	010
 Int	18446744073709551615
!Int	1.0
!Int	0.1
!Int	1.2.3
!Int	0.0
!Int	0.1.0
!Int	0b00
!Int	0e
!Int	0e0
!Int	0e1
!Int	1e0
!Int	0 but true
!Int	1 foobar

Trivial values are consistent, values with leading/trailing spaces and a special value "0 but true" are controversial.

IMHO, the result from Mouse::PurePerl looks intuitively correct and we should change Mouse::XS to match that result -- but I also pondering the counter-argument here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions