[Moose-commits] r7139 - in Moose/trunk: . lib/Moose/Meta
sartak at code2.0beta.co.uk
sartak at code2.0beta.co.uk
Sun Dec 21 23:10:19 GMT 2008
Author: sartak
Date: 2008-12-21 15:10:19 -0800 (Sun, 21 Dec 2008)
New Revision: 7139
Modified:
Moose/trunk/
Moose/trunk/Changes
Moose/trunk/lib/Moose/Meta/Attribute.pm
Log:
r77724 at onn: sartak | 2008-12-21 18:10:07 -0500
Moose::Meta::Attribute->check_type_constraint
Property changes on: Moose/trunk
___________________________________________________________________
Name: svk:merge
- 08e7d58d-de06-4458-8c15-335e402ab116:/local/Moose:77722
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/BUILDARGS:4770
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/Moose-dumb_roles:1727
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/Moose-moosex_compile_support:3337
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/Moose-real_class_meta_type_constraint:3322
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/deprototype:6072
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/inline_wrapped_constructor:3777
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/meta-role-helper:5585
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/method-changes:5953
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/moose-exporter:5196
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/parameterize_constructor_role:5927
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/parameterized_type_fixes:6365
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/predicate_fix:2940
48425d73-d564-4cf1-a4fc-b7d19ba782dc:/local/Moose:54077
f7901bf9-e7b5-442b-97a4-4d7fd5798e10:/local/moose/Moose:41354
+ 08e7d58d-de06-4458-8c15-335e402ab116:/local/Moose:77724
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/BUILDARGS:4770
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/Moose-dumb_roles:1727
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/Moose-moosex_compile_support:3337
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/Moose-real_class_meta_type_constraint:3322
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/deprototype:6072
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/inline_wrapped_constructor:3777
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/meta-role-helper:5585
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/method-changes:5953
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/moose-exporter:5196
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/parameterize_constructor_role:5927
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/parameterized_type_fixes:6365
3efe9002-19ed-0310-8735-a98156148065:/Moose/branches/predicate_fix:2940
48425d73-d564-4cf1-a4fc-b7d19ba782dc:/local/Moose:54077
f7901bf9-e7b5-442b-97a4-4d7fd5798e10:/local/moose/Moose:41354
Modified: Moose/trunk/Changes
===================================================================
--- Moose/trunk/Changes 2008-12-21 23:00:34 UTC (rev 7138)
+++ Moose/trunk/Changes 2008-12-21 23:10:19 UTC (rev 7139)
@@ -5,6 +5,8 @@
- Always inline predicate and clearer methods (Sartak)
* Moose::Meta::Attribute
- Support for parameterized traits (Sartak)
+ - check_type_constraint method to avoid duplication and
+ enhance extensibility (Sartak)
* Moose::Meta::Class
- Tests (but no support yet) for parameterized traits (Sartak)
Modified: Moose/trunk/lib/Moose/Meta/Attribute.pm
===================================================================
--- Moose/trunk/lib/Moose/Meta/Attribute.pm 2008-12-21 23:00:34 UTC (rev 7138)
+++ Moose/trunk/lib/Moose/Meta/Attribute.pm 2008-12-21 23:10:19 UTC (rev 7139)
@@ -411,11 +411,7 @@
if ($self->should_coerce && $type_constraint->has_coercion) {
$val = $type_constraint->coerce($val);
}
- $type_constraint->check($val)
- || $self->throw_error("Attribute ("
- . $self->name
- . ") does not pass the type constraint because: "
- . $type_constraint->get_message($val), data => $val, object => $instance);
+ $self->check_type_constraint($val, instance => $instance);
}
$self->set_initial_value($instance, $val);
@@ -467,11 +463,7 @@
if ($type_constraint) {
$val = $type_constraint->coerce($val)
if $can_coerce;
- $type_constraint->check($val)
- || $self->throw_error("Attribute ("
- . $slot_name
- . ") does not pass the type constraint because: "
- . $type_constraint->get_message($val), data => $val, object => $instance);
+ $self->check_type_constraint($val, object => $instance);
}
$meta_instance->set_slot_value($instance, $slot_name, $val);
};
@@ -535,10 +527,7 @@
my $type_constraint = $self->type_constraint;
$value = $type_constraint->coerce($value)
if ($self->should_coerce);
- $type_constraint->check($value)
- || $self->throw_error("Attribute (" . $self->name
- . ") does not pass the type constraint because: "
- . $type_constraint->get_message($value), type_constraint => $type_constraint, data => $value);
+ $self->check_type_constraint($value);
}
$self->set_initial_value($instance, $value);
}
@@ -731,6 +720,21 @@
);
}
+sub check_type_constraint {
+ my $self = shift;
+ my $val = shift;
+
+ return 1 if !$self->has_type_constraint;
+
+ my $type_constraint = $self->type_constraint;
+
+ $type_constraint->check($val)
+ || $self->throw_error("Attribute ("
+ . $self->name
+ . ") does not pass the type constraint because: "
+ . $type_constraint->get_message($val), data => $val, @_);
+}
+
package Moose::Meta::Attribute::Custom::Moose;
sub register_implementation { 'Moose::Meta::Attribute' }
@@ -846,6 +850,11 @@
more information on what you can do with this, see the documentation
for L<Moose::Meta::TypeConstraint>.
+=item B<check_type_constraint>
+
+Confirms that the given value is valid under this attribute's type
+constraint, otherwise throws an error.
+
=item B<has_handles>
Returns true if this meta-attribute performs delegation.
More information about the Moose-commits
mailing list