From: Stevan Little Date: Sun, 27 May 2007 17:55:22 +0000 (+0000) Subject: fixing the authors lists and adding the ClassName type constraint X-Git-Tag: 0_22^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9af1d28be417ff8c05dea73e3a7e7f8f2b92bb26;p=gitmo%2FMoose.git fixing the authors lists and adding the ClassName type constraint --- diff --git a/Changes b/Changes index 0cee34b..f68052e 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,9 @@ Revision history for Perl extension Moose - fix for prototype undecl issue when type constraint utils loaded before consumers (e.g. Moose::Meta::Attribute) by predeclaring prototypes in TC utils + - added the ClassName type constraint, this checks for strings + which will respond true to ->isa(UNIVERSAL). + - added tests and docs for this * Moose::Meta::Method::Accessor - coerce and lazy now work together correctly, thanks to diff --git a/lib/Moose.pm b/lib/Moose.pm index 327b1c8..f769571 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -775,9 +775,33 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE -Christian Hansen Echansen@cpan.orgE +B -Yuval Kogman Enothingmuch@woobling.orgE +Aankhen + +Adam (Alias) Kennedy + +Anders (Debolaz) Nor Berle + +Christian (chansen) Hansen + +Eric (ewilhelm) Wilhelm + +Guillermo (groditi) Roditi + +Jess (castaway) Robinson + +Matt (mst) Trout + +Robert (phaylon) Sedlacek + +Robert (rlb3) Boone + +Scott (konobi) McWhirter + +Yuval (nothingmuch) Kogman + +... and many other #moose folks =head1 COPYRIGHT AND LICENSE diff --git a/lib/Moose/Meta/Method.pm b/lib/Moose/Meta/Method.pm index 342210b..66ba567 100644 --- a/lib/Moose/Meta/Method.pm +++ b/lib/Moose/Meta/Method.pm @@ -34,8 +34,6 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE -Yuval Kogman Enothingmuch@woobling.comE - =head1 COPYRIGHT AND LICENSE Copyright 2006, 2007 by Infinity Interactive, Inc. diff --git a/lib/Moose/Meta/Method/Overriden.pm b/lib/Moose/Meta/Method/Overriden.pm index 232a3e3..0dcd133 100644 --- a/lib/Moose/Meta/Method/Overriden.pm +++ b/lib/Moose/Meta/Method/Overriden.pm @@ -37,8 +37,6 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE -Yuval Kogman Enothingmuch@woobling.comE - =head1 COPYRIGHT AND LICENSE Copyright 2006, 2007 by Infinity Interactive, Inc. diff --git a/lib/Moose/Meta/Role/Method.pm b/lib/Moose/Meta/Role/Method.pm index 8efa923..d937311 100644 --- a/lib/Moose/Meta/Role/Method.pm +++ b/lib/Moose/Meta/Role/Method.pm @@ -35,8 +35,6 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE -Yuval Kogman Enothingmuch@woobling.comE - =head1 COPYRIGHT AND LICENSE Copyright 2006, 2007 by Infinity Interactive, Inc. diff --git a/lib/Moose/Meta/TypeConstraint/Union.pm b/lib/Moose/Meta/TypeConstraint/Union.pm index 0bc4014..162b80a 100644 --- a/lib/Moose/Meta/TypeConstraint/Union.pm +++ b/lib/Moose/Meta/TypeConstraint/Union.pm @@ -194,8 +194,6 @@ to cpan-RT. Stevan Little Estevan@iinteractive.comE -Yuval Kogman Enothingmuch@woobling.comE - =head1 COPYRIGHT AND LICENSE Copyright 2006, 2007 by Infinity Interactive, Inc. diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index d984085..9dfa98b 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -245,6 +245,11 @@ subtype 'Role' => as 'Object' => where { $_->can('does') } => optimize_as { blessed($_[0]) && $_[0]->can('does') }; + +subtype 'ClassName' + => as 'Str' + => where { eval { $_->isa('UNIVERSAL') } } + => optimize_as { !ref($_[0]) && eval { $_[0]->isa('UNIVERSAL') } }; { my @BUILTINS = list_all_type_constraints(); @@ -334,6 +339,7 @@ could probably use some work, but it works for me at the moment. Num Int Str + ClassName Ref ScalarRef ArrayRef @@ -350,6 +356,12 @@ Suggestions for improvement are welcome. B The C type constraint does not work correctly in every occasion, please use it sparringly. +B The C type constraint is simply a subtype +of string which responds true to C. This means +that your class B be loaded for this type constraint to +pass. I know this is not ideal for all, but it is a saner +restriction then most others. + =head2 Use with Other Constraint Modules This module should play fairly nicely with other constraint diff --git a/t/052_util_std_type_constraints.t b/t/052_util_std_type_constraints.t index b126cbf..d4cdb5e 100644 --- a/t/052_util_std_type_constraints.t +++ b/t/052_util_std_type_constraints.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 254; +use Test::More tests => 269; use Test::Exception; use Scalar::Util (); @@ -299,4 +299,20 @@ ok(!defined Role(bless {}, 'Foo'), '... Role accepts anything which is not ok(defined Role(bless {}, 'My::Role'), '... Role accepts anything which is not a Role'); ok(!defined Role(undef), '... Role accepts anything which is not a Role'); +ok(!defined ClassName(0), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName(100), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName(''), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName('Baz'), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName([]), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName({}), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName(sub {}), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName($SCALAR_REF), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName($fh), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName($GLOB_REF), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName(qr/../), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName(bless {}, 'Foo'), '... ClassName rejects anything which is not a ClassName'); +ok(!defined ClassName(undef), '... ClassName rejects anything which is not a ClassName'); +ok(defined ClassName('UNIVERSAL'), '... ClassName accepts anything which is a ClassName'); +ok(defined ClassName('Moose::Meta::TypeConstraint'), '... ClassName accepts anything which is a ClassName'); + close($fh) || die "Could not close the filehandle $0 for test";