From: Stevan Little Date: Fri, 19 Oct 2007 13:02:22 +0000 (+0000) Subject: fixing the type constraints X-Git-Tag: 0_27~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3796382ab39b1382f228886a2773198bb0018f0e;p=gitmo%2FMoose.git fixing the type constraints --- diff --git a/Changes b/Changes index b092c61..43b8c22 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,14 @@ Revision history for Perl extension Moose methods from a class (thanks to confound). - added tests for this + * Moose::Util::TypeConstraint + - fixed the type notation parser so that + the | always creates a union and so is + no longer a valid type char (thanks to + konobi, mugwump and #moose for working + this one out.) + - added more tests for this + 0.26 Thurs. Sept. 27, 2007 == New Features == diff --git a/lib/Moose.pm b/lib/Moose.pm index 2994965..7b3bad7 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -8,9 +8,9 @@ our $VERSION = '0.27'; our $AUTHORITY = 'cpan:STEVAN'; use Scalar::Util 'blessed', 'reftype'; -use Carp 'confess'; -use Sub::Name 'subname'; -use B 'svref_2object'; +use Carp 'confess'; +use Sub::Name 'subname'; +use B 'svref_2object'; use Sub::Exporter; diff --git a/lib/Moose/Cookbook/FAQ.pod b/lib/Moose/Cookbook/FAQ.pod index 88f61e5..a3106b2 100644 --- a/lib/Moose/Cookbook/FAQ.pod +++ b/lib/Moose/Cookbook/FAQ.pod @@ -11,7 +11,7 @@ Moose::Cookbook::FAQ - Frequently asked questions about Moose =head3 Is Moose "production ready"? -Yes. I have two medium-to-large-ish web applications in +Yes. I have three medium-to-large-ish web applications in production using Moose, they have been running without issue now for almost a year. @@ -57,14 +57,10 @@ conversion to XS. =head3 When will Moose 1.0 be ready? -I had originally said it would be end of 2006, but various bits -of $work kept me too busy. At this point, I think we are getting -pretty close and I will likely declare 1.0 within the next few -releases. +It is right now, I just haven't bumped the version number up yet. -When will that be? Hard to say really, but honestly, it is ready -to use now, the difference between now and 1.0 will be pretty -minimal. +I still have some more internal TODO items I would like to complete +before I would even consider bumping it to 1.0. =head2 Constructors diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 3f9ca16..e160ee3 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -9,7 +9,7 @@ use Scalar::Util 'blessed', 'reftype'; use B 'svref_2object'; use Sub::Exporter; -our $VERSION = '0.14'; +our $VERSION = '0.15'; our $AUTHORITY = 'cpan:STEVAN'; ## -------------------------------------------------------- @@ -301,14 +301,14 @@ sub _install_type_coercions ($$) { use re "eval"; - my $valid_chars = qr{[\w:|]}; + my $valid_chars = qr{[\w:]}; my $type_atom = qr{ $valid_chars+ }; my $type = qr{ $valid_chars+ (?: \[ (??{$any}) \] )? }x; my $type_capture_parts = qr{ ($valid_chars+) (?: \[ ((??{$any})) \] )? }x; my $type_with_parameter = qr{ $valid_chars+ \[ (??{$any}) \] }x; - my $op_union = qr{ \s+ \| \s+ }x; + my $op_union = qr{ \s* \| \s* }x; my $union = qr{ $type (?: $op_union $type )+ }x; our $any = qr{ $type | $union }x; diff --git a/t/040_type_constraints/009_union_types_and_coercions.t b/t/040_type_constraints/009_union_types_and_coercions.t index c9a42b8..147859b 100644 --- a/t/040_type_constraints/009_union_types_and_coercions.t +++ b/t/040_type_constraints/009_union_types_and_coercions.t @@ -51,7 +51,7 @@ BEGIN { has 'raw_body' => ( is => 'rw', - isa => 'IO::String | IO::File', + isa => 'IO::String|IO::File', coerce => 1, default => sub { IO::String->new() }, ); diff --git a/t/040_type_constraints/013_advanced_type_creation.t b/t/040_type_constraints/013_advanced_type_creation.t index 9d15c7a..2bf2273 100644 --- a/t/040_type_constraints/013_advanced_type_creation.t +++ b/t/040_type_constraints/013_advanced_type_creation.t @@ -17,7 +17,7 @@ my $r = Moose::Util::TypeConstraints->get_type_constraint_registry; # Array of Ints or Strings -my $array_of_ints_or_strings = Moose::Util::TypeConstraints::create_parameterized_type_constraint('ArrayRef[Int | Str]'); +my $array_of_ints_or_strings = Moose::Util::TypeConstraints::create_parameterized_type_constraint('ArrayRef[Int|Str]'); isa_ok($array_of_ints_or_strings, 'Moose::Meta::TypeConstraint::Parameterized'); ok($array_of_ints_or_strings->check([ 1, 'two', 3 ]), '... this passed the type check'); @@ -46,7 +46,7 @@ $r->add_type_constraint($array_of_ints_or_hash_ref); # we can't build this using the simplistic parser # we have, so we have to do it by hand - SL -my $pure_insanity = Moose::Util::TypeConstraints::create_type_constraint_union('ArrayRef[Int | Str] | ArrayRef[Int | HashRef]'); +my $pure_insanity = Moose::Util::TypeConstraints::create_type_constraint_union('ArrayRef[Int|Str] | ArrayRef[Int | HashRef]'); isa_ok($pure_insanity, 'Moose::Meta::TypeConstraint::Union'); ok($pure_insanity->check([ 1, {}, 3 ]), '... this passed the type check'); diff --git a/t/040_type_constraints/014_type_notation_parser.t b/t/040_type_constraints/014_type_notation_parser.t index 5c3c9ba..3487dc7 100644 --- a/t/040_type_constraints/014_type_notation_parser.t +++ b/t/040_type_constraints/014_type_notation_parser.t @@ -3,12 +3,19 @@ use strict; use warnings; -use Test::More tests => 26; +use Test::More tests => 41; BEGIN { use_ok("Moose::Util::TypeConstraints"); } +=pod + +This is a good canidate for LectroTest +Volunteers welcome :) + +=cut + ## check the containers ok(Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), @@ -18,6 +25,7 @@ ok(Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), 'ArrayRef[Foo | Int]', 'ArrayRef[ArrayRef[Int]]', 'ArrayRef[ArrayRef[Int | Foo]]', + 'ArrayRef[ArrayRef[Int|Str]]', ); ok(!Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), @@ -31,10 +39,12 @@ ok(!Moose::Util::TypeConstraints::_detect_parameterized_type_constraint($_), my %split_tests = ( 'ArrayRef[Foo]' => [ 'ArrayRef', 'Foo' ], 'ArrayRef[Foo | Int]' => [ 'ArrayRef', 'Foo | Int' ], + 'ArrayRef[Foo|Int]' => [ 'ArrayRef', 'Foo|Int' ], # these will get processed with recusion, # so we only need to detect it once 'ArrayRef[ArrayRef[Int]]' => [ 'ArrayRef', 'ArrayRef[Int]' ], 'ArrayRef[ArrayRef[Int | Foo]]' => [ 'ArrayRef', 'ArrayRef[Int | Foo]' ], + 'ArrayRef[ArrayRef[Int|Str]]' => [ 'ArrayRef', 'ArrayRef[Int|Str]' ], ); is_deeply( @@ -50,11 +60,17 @@ ok(Moose::Util::TypeConstraints::_detect_type_constraint_union($_), '... this correctly detected union (' . $_ . ')') for ( 'Int | Str', + 'Int|Str', 'ArrayRef[Foo] | Int', + 'ArrayRef[Foo]|Int', 'Int | ArrayRef[Foo]', + 'Int|ArrayRef[Foo]', 'ArrayRef[Foo | Int] | Str', + 'ArrayRef[Foo|Int]|Str', 'Str | ArrayRef[Foo | Int]', + 'Str|ArrayRef[Foo|Int]', 'Some|Silly|Name|With|Pipes | Int', + 'Some|Silly|Name|With|Pipes|Int', ); ok(!Moose::Util::TypeConstraints::_detect_type_constraint_union($_), @@ -62,17 +78,23 @@ ok(!Moose::Util::TypeConstraints::_detect_type_constraint_union($_), for ( 'Int', 'ArrayRef[Foo | Int]', - 'Some|Silly|Name|With|Pipes', + 'ArrayRef[Foo|Int]', ); { my %split_tests = ( 'Int | Str' => [ 'Int', 'Str' ], + 'Int|Str' => [ 'Int', 'Str' ], 'ArrayRef[Foo] | Int' => [ 'ArrayRef[Foo]', 'Int' ], + 'ArrayRef[Foo]|Int' => [ 'ArrayRef[Foo]', 'Int' ], 'Int | ArrayRef[Foo]' => [ 'Int', 'ArrayRef[Foo]' ], + 'Int|ArrayRef[Foo]' => [ 'Int', 'ArrayRef[Foo]' ], 'ArrayRef[Foo | Int] | Str' => [ 'ArrayRef[Foo | Int]', 'Str' ], + 'ArrayRef[Foo|Int]|Str' => [ 'ArrayRef[Foo|Int]', 'Str' ], 'Str | ArrayRef[Foo | Int]' => [ 'Str', 'ArrayRef[Foo | Int]' ], - 'Some|Silly|Name|With|Pipes | Int' => [ 'Some|Silly|Name|With|Pipes', 'Int' ], + 'Str|ArrayRef[Foo|Int]' => [ 'Str', 'ArrayRef[Foo|Int]' ], + 'Some|Silly|Name|With|Pipes | Int' => [ 'Some', 'Silly', 'Name', 'With', 'Pipes', 'Int' ], + 'Some|Silly|Name|With|Pipes|Int' => [ 'Some', 'Silly', 'Name', 'With', 'Pipes', 'Int' ], ); is_deeply(