Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible conflict with Optional in Type::Tiny #1

Closed
jandrew opened this issue Jul 22, 2014 · 2 comments
Closed

Possible conflict with Optional in Type::Tiny #1

jandrew opened this issue Jul 22, 2014 · 2 comments

Comments

@jandrew
Copy link

jandrew commented Jul 22, 2014

I am seeing fails for classes using Types::Standard and Optional when Type::Tiny::XS (0.008) is installed. The following case passes when Type::Tiny::XS is not installed and fails for not enough arguments when it is. I don't know any XS so I'm not exactly sure what part is failing and what parts are not essential to the test case. I run Strawberry perl 5.14 on windows 64 but I am getting fails for linux on all versions of perl for modules I have posted to CPAN(updated) with Types::Standard qw( Optional ) for apparently the same reason (inferred).

#!perl
package MyTest;
use strict;
use warnings;
use Type::Utils 0.046 -all;
use Test::Most;
eval "use Type::Tiny::XS";
use Type::Library 0.046
    -base,
    -declare => qw(
        TestDictionary SuperClassesList NameSpace
    );
use Types::Standard 0.046 -types;

declare NameSpace,
    as Str,
    where{ $_ =~ /^[A-Za-z:]+$/ },
    message{ "-$_- does not match: " . qr/^[A-Za-z:]+$/ };

declare SuperClassesList,
    as ArrayRef[ ClassName ],
    where{ scalar( @$_ ) > 0 };

declare TestDictionary,
    as Dict[
        package => Optional[ NameSpace ],
        superclasses => Optional[ SuperClassesList ],
    ],;

ok        TestDictionary->( { package => 'My::Package' } ), 
                "Test TestDictionary";
done_testing();

The error message with ~::XS installed is;

Too few arguments for type constraint check functions at C:/strawberry/perl/site/lib/Type/Tiny.pm line 358.
@tobyink
Copy link
Owner

tobyink commented Jul 22, 2014

Declaring inline_as for the first two types allows you to work around the issue:

use strict;
use warnings;
use Test::Most;

{
    package MyTest;
    use Type::Utils 0.046 -all;
    use Type::Library 0.046
        -base,
        -declare => qw(TestDictionary SuperClassesList NameSpace);
    use Types::Standard 0.046 -types;

    declare NameSpace,
        as Str,
        where { $_ =~ /^[A-Za-z:]+$/ },
        inline_as { undef, "$_ =~ /^[A-Za-z:]+\$/" },
        message { "-$_- does not match: " . qr/^[A-Za-z:]+$/ };

    declare SuperClassesList,
        as ArrayRef[ ClassName ],
        inline_as { undef, "\@{$_} > 0" },
        where { scalar( @$_ ) > 0 };

    declare TestDictionary, as Dict[
        package      => Optional[ NameSpace ],
        superclasses => Optional[ SuperClassesList ],
    ];
}

ok(
    MyTest::TestDictionary->check( { package => 'My::Package' } ),
    "Test TestDictionary"
);

diag MyTest::TestDictionary->inline_check('$dict');

done_testing;

@tobyink
Copy link
Owner

tobyink commented Jul 22, 2014

Fixed in 0.010 (I hope).

@tobyink tobyink closed this as completed Jul 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants