From: Stevan Little Date: Tue, 21 Mar 2006 16:23:48 +0000 (+0000) Subject: more-tweaks X-Git-Tag: 0_05~70 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=34a66aa3423e251341c77ba790950eae4fbcfff9;p=gitmo%2FMoose.git more-tweaks --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index a2e9672..260796a 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -18,8 +18,8 @@ __PACKAGE__->meta->add_attribute('type_constraint' => ( predicate => 'has_type_constraint', )); -sub has_coercion { (shift)->coerce() ? 1 : 0 } -sub has_weak_ref { (shift)->weak_ref() ? 1 : 0 } +sub should_coerce { (shift)->coerce() ? 1 : 0 } +sub is_weak_ref { (shift)->weak_ref() ? 1 : 0 } __PACKAGE__->meta->add_before_method_modifier('new' => sub { my (undef, undef, %options) = @_; @@ -34,7 +34,7 @@ __PACKAGE__->meta->add_before_method_modifier('new' => sub { sub generate_accessor_method { my ($self, $attr_name) = @_; if ($self->has_type_constraint) { - if ($self->has_weak_ref) { + if ($self->is_weak_ref) { return sub { if (scalar(@_) == 2) { (defined $self->type_constraint->check($_[1])) @@ -47,7 +47,7 @@ sub generate_accessor_method { }; } else { - if ($self->has_coercion) { + if ($self->should_coerce) { return sub { if (scalar(@_) == 2) { my $val = $self->type_constraint->coercion->coerce($_[1]); @@ -73,7 +73,7 @@ sub generate_accessor_method { } } else { - if ($self->has_weak_ref) { + if ($self->is_weak_ref) { return sub { if (scalar(@_) == 2) { $_[0]->{$attr_name} = $_[1]; @@ -94,7 +94,7 @@ sub generate_accessor_method { sub generate_writer_method { my ($self, $attr_name) = @_; if ($self->has_type_constraint) { - if ($self->has_weak_ref) { + if ($self->is_weak_ref) { return sub { (defined $self->type_constraint->check($_[1])) || confess "Attribute ($attr_name) does not pass the type contraint with '$_[1]'" @@ -104,7 +104,7 @@ sub generate_writer_method { }; } else { - if ($self->has_coercion) { + if ($self->should_coerce) { return sub { my $val = $self->type_constraint->coercion->coerce($_[1]); (defined $self->type_constraint->check($val)) @@ -124,7 +124,7 @@ sub generate_writer_method { } } else { - if ($self->has_weak_ref) { + if ($self->is_weak_ref) { return sub { $_[0]->{$attr_name} = $_[1]; weaken($_[0]->{$attr_name}); @@ -171,13 +171,13 @@ extensions. =item B -=item B +=item B =item B =item B -=item B +=item B =back diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 4daa68b..76f42f3 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -23,7 +23,7 @@ sub construct_instance { $val ||= $attr->default($instance) if $attr->has_default; if (defined $val) { if ($attr->has_type_constraint) { - if ($attr->has_coercion && $attr->type_constraint->has_coercion) { + if ($attr->should_coerce && $attr->type_constraint->has_coercion) { $val = $attr->type_constraint->coercion->coerce($val); } (defined($attr->type_constraint->check($val))) diff --git a/lib/Moose/Meta/TypeCoercion.pm b/lib/Moose/Meta/TypeCoercion.pm index fea1b7d..2120734 100644 --- a/lib/Moose/Meta/TypeCoercion.pm +++ b/lib/Moose/Meta/TypeCoercion.pm @@ -8,7 +8,7 @@ use metaclass; use Carp 'confess'; use Moose::Meta::Attribute; -use Moose::Util::TypeConstraints; +use Moose::Util::TypeConstraints '-no-export'; our $VERSION = '0.01'; diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 00a4760..b70c870 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -15,6 +15,7 @@ use Moose::Meta::TypeCoercion; sub import { shift; my $pkg = shift || caller(); + return if $pkg eq '-no-export'; no strict 'refs'; foreach my $export (qw(type subtype as where coerce from via find_type_constraint)) { *{"${pkg}::${export}"} = \&{"${export}"};