- 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
Stevan Little E<lt>stevan@iinteractive.comE<gt>
-Christian Hansen E<lt>chansen@cpan.orgE<gt>
+B<with contributions from:>
-Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
+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
Stevan Little E<lt>stevan@iinteractive.comE<gt>
-Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
-
=head1 COPYRIGHT AND LICENSE
Copyright 2006, 2007 by Infinity Interactive, Inc.
Stevan Little E<lt>stevan@iinteractive.comE<gt>
-Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
-
=head1 COPYRIGHT AND LICENSE
Copyright 2006, 2007 by Infinity Interactive, Inc.
Stevan Little E<lt>stevan@iinteractive.comE<gt>
-Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
-
=head1 COPYRIGHT AND LICENSE
Copyright 2006, 2007 by Infinity Interactive, Inc.
Stevan Little E<lt>stevan@iinteractive.comE<gt>
-Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
-
=head1 COPYRIGHT AND LICENSE
Copyright 2006, 2007 by Infinity Interactive, Inc.
=> 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();
Num
Int
Str
+ ClassName
Ref
ScalarRef
ArrayRef
B<NOTE:> The C<Undef> type constraint does not work correctly
in every occasion, please use it sparringly.
+B<NOTE:> The C<ClassName> type constraint is simply a subtype
+of string which responds true to C<isa('UNIVERSAL')>. This means
+that your class B<must> 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
use strict;
use warnings;
-use Test::More tests => 254;
+use Test::More tests => 269;
use Test::Exception;
use Scalar::Util ();
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";