BSD, but kept the parts that normalize names.
- Add abridged documentation for builder/default/initializer/
predicate, and link to more details sections in
Class::MOP::Attribute. (t0m)
+
* Moose::Util::TypeConstraints
- removed prototypes from all but the &-based stuff (mst)
+
* Moose::Util::TypeConstraints
- Creating a anonymous subtype with both a constraint and a
message failed with a very unhelpful error, but should just
work. Reported by t0m. (Dave Rolsky)
+
* Tests
- Some tests that used Test::Warn if it was available failed
with older versions of Test::Warn. Reported by Fayland. (Dave
lazy_build. (t0m)
- Test behavior of equals/is_a_type_of/is_a_subtype_of for all
kinds of supported type. (t0m)
+
* Moose::Meta::Class
- In create(), do not pass "roles" option to the superclass
- added related test that creates an anon metaclass with
a required attribute
+
* Moose::Meta::TypeConstraint::Class
* Moose::Meta::TypeConstraint::Role
- Unify behavior of equals/is_a_type_of/is_a_subtype_of with
other types (as per change in 0.55_02). (t0m)
+
* Moose::Meta::TypeConstraint::Registry
- Fix warning when dealing with unknown type names (t0m)
+ * Moose::Util::TypeConstraints
+ - Reverted changes from 0.58 related to handle parameterized
+ types. This caused random failures on BSD and Win32 systems,
+ apparently related to the regex engine. This means that Moose
+ can no longer parse structured type constraints like
+ ArrayRef[Int,Int] or HashRef[name=>Str]. This will be
+ supported in a slightly different way via MooseX::Types some
+ time in the future. (Dave Rolsky)
+
0.58 Sat September 20, 2008
!! This release has an incompatible change regarding !!
!! how roles add methods to a class !!
t/040_type_constraints/024_role_type_constraint.t
t/040_type_constraints/025_type_coersion_on_lazy_attributes.t
t/040_type_constraints/026_normalize_type_name.t
-t/040_type_constraints/027_parameterize_from.t
+t/040_type_constraints/029_define_type_twice_throws.t
t/050_metaclasses/001_custom_attr_meta_with_roles.t
t/050_metaclasses/002_custom_attr_meta_as_role.t
t/050_metaclasses/003_moose_w_metaclass.t
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::TypeConstraint';
-use Moose::Meta::TypeConstraint::Parameterized;
-use Moose::Util::TypeConstraints ();
__PACKAGE__->meta->add_attribute('constraint_generator' => (
accessor => 'constraint_generator',
};
}
-sub _parse_type_parameter {
- my ($self, $type_parameter) = @_;
- return Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($type_parameter);
-}
-
-sub parameterize {
- my ($self, $type_parameter) = @_;
-
- my $contained_tc = $self->_parse_type_parameter($type_parameter);
-
- if ( $contained_tc->isa('Moose::Meta::TypeConstraint') ) {
- my $tc_name = $self->name . '[' . $contained_tc->name . ']';
- return Moose::Meta::TypeConstraint::Parameterized->new(
- name => $tc_name,
- parent => $self,
- type_parameter => $contained_tc,
- );
- }
- else {
- Moose->throw_error("The type parameter must be a Moose meta type");
- }
-}
-
1;
=item B<generate_constraint_for>
-=item B<parameterize>
-
-Given a single type constraint string, this method parses the string
-and parameterizes the type based on the parsed string.
-
=item B<meta>
=back
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(
- name => (join '|' => map { $_->name } @{$options{type_constraints}}),
+ name => (join '|' => sort map { $_->name } @{$options{type_constraints}}),
parent => undef,
message => undef,
hand_optimized_type_constraint => undef,
(scalar @type_constraint_names >= 2)
|| Moose->throw_error("You must pass in at least 2 type names to make a union");
- my @type_constraints = sort {$a->name cmp $b->name} map {
+ my @type_constraints = map {
find_or_parse_type_constraint($_) ||
Moose->throw_error("Could not locate type constraint ($_) for the union");
} @type_constraint_names;
-
+
return Moose::Meta::TypeConstraint::Union->new(
type_constraints => \@type_constraints
);
(defined $base_type && defined $type_parameter)
|| Moose->throw_error("Could not parse type name ($type_constraint_name) correctly");
- if ($REGISTRY->has_type_constraint($base_type)) {
- my $base_type_tc = $REGISTRY->get_type_constraint($base_type);
- return _create_parameterized_type_constraint(
- $base_type_tc,
- $type_parameter,
- );
- } else {
- Moose->throw_error("Could not locate the base type ($base_type)");
- }
-}
-
-sub _create_parameterized_type_constraint {
- my ( $base_type_tc, $type_parameter ) = @_;
- if ( $base_type_tc->can('parameterize') ) {
- return $base_type_tc->parameterize($type_parameter);
- }
- else {
- return Moose::Meta::TypeConstraint::Parameterized->new(
- name => $base_type_tc->name . '[' . $type_parameter . ']',
- parent => $base_type_tc,
- type_parameter =>
- find_or_create_isa_type_constraint($type_parameter),
- );
- }
+ # We need to get the relevant type constraints and use them to
+ # create the name to ensure that we end up with the fully
+ # normalized name, because the user could've passed something like
+ # HashRef[Str|Int] and we want to make that HashRef[Int|Str].
+ my $base_type_tc = $REGISTRY->get_type_constraint($base_type)
+ || Moose->throw_error("Could not locate the base type ($base_type)");
+ my $parameter_tc = find_or_create_isa_type_constraint($type_parameter)
+ || Moose->throw_error("Could not locate the parameter type ($type_parameter)");
+
+ return Moose::Meta::TypeConstraint::Parameterized->new(
+ name => $base_type_tc->name . '[' . $parameter_tc->name . ']',
+ parent => $base_type_tc,
+ type_parameter => $parameter_tc,
+ );
}
#should we also support optimized checks?
}
sub normalize_type_constraint_name {
- my $type_constraint_name = shift @_;
+ my $type_constraint_name = shift;
$type_constraint_name =~ s/\s//g;
return $type_constraint_name;
}
my $op_union = qr{ \s* \| \s* }x;
my $union = qr{ $type (?: $op_union $type )+ }x;
- ## New Stuff for structured types.
- my $comma = qr{,};
- my $indirection = qr{=>};
- my $divider_ops = qr{ $comma | $indirection }x;
- my $structure_divider = qr{\s* $divider_ops \s*}x;
- my $structure_elements = qr{ ($type $structure_divider*)+ }x;
-
- $any = qr{ $type | $union | $structure_elements }x;
+ $any = qr{ $type | $union }x;
sub _parse_parameterized_type_constraint {
{ no warnings 'void'; $any; } # force capture of interpolated lexical
- my($base, $elements) = ($_[0] =~ m{ $type_capture_parts }x);
- return ($base,$elements);
+ $_[0] =~ m{ $type_capture_parts }x;
+ return ($1, $2);
}
sub _detect_parameterized_type_constraint {
+++ /dev/null
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use Test::More tests => 12;
-use Test::Exception;
-
-BEGIN {
- use_ok('Moose::Util::TypeConstraints');
-}
-
-# testing the parameterize method
-
-{
- my $parameterizable = subtype 'parameterizable_hashref', as 'HashRef';
-
- my $parameterized = subtype 'parameterized_hashref', as 'HashRef[Int]';
-
- my $int = Moose::Util::TypeConstraints::find_type_constraint('Int');
-
- my $from_parameterizable = $parameterizable->parameterize($int);
-
- isa_ok $parameterizable,
- 'Moose::Meta::TypeConstraint::Parameterizable', =>
- 'Got expected type instance';
-
- package Test::Moose::Meta::TypeConstraint::Parameterizable;
- use Moose;
-
- has parameterizable => ( is => 'rw', isa => $parameterizable );
- has parameterized => ( is => 'rw', isa => $parameterized );
- has from_parameterizable => ( is => 'rw', isa => $from_parameterizable );
-}
-
-# Create and check a dummy object
-
-ok my $params = Test::Moose::Meta::TypeConstraint::Parameterizable->new() =>
- 'Create Dummy object for testing';
-
-isa_ok $params, 'Test::Moose::Meta::TypeConstraint::Parameterizable' =>
- 'isa correct type';
-
-# test parameterizable
-
-lives_ok sub {
- $params->parameterizable( { a => 'Hello', b => 'World' } );
-} => 'No problem setting parameterizable';
-
-is_deeply $params->parameterizable,
- { a => 'Hello', b => 'World' } => 'Got expected values';
-
-# test parameterized
-
-lives_ok sub {
- $params->parameterized( { a => 1, b => 2 } );
-} => 'No problem setting parameterized';
-
-is_deeply $params->parameterized, { a => 1, b => 2 } => 'Got expected values';
-
-throws_ok sub {
- $params->parameterized( { a => 'Hello', b => 'World' } );
- }, qr/Attribute \(parameterized\) does not pass the type constraint/ =>
- 'parameterized throws expected error';
-
-# test from_parameterizable
-
-lives_ok sub {
- $params->from_parameterizable( { a => 1, b => 2 } );
-} => 'No problem setting from_parameterizable';
-
-is_deeply $params->from_parameterizable,
- { a => 1, b => 2 } => 'Got expected values';
-
-throws_ok sub {
- $params->from_parameterizable( { a => 'Hello', b => 'World' } );
- },
- qr/Attribute \(from_parameterizable\) does not pass the type constraint/
- => 'from_parameterizable throws expected error';