From: Stevan Little Date: Tue, 21 Mar 2006 01:57:50 +0000 (+0000) Subject: cleaning up X-Git-Tag: 0_05~75 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=82168dbb31f995cc0f747d3d430325d63360384c;p=gitmo%2FMoose.git cleaning up --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 5d6213b..d2fc8b1 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -7,38 +7,26 @@ use warnings; use Scalar::Util 'weaken', 'reftype'; use Carp 'confess'; -use Moose::Util::TypeConstraints ':no_export'; - our $VERSION = '0.02'; use base 'Class::MOP::Attribute'; -Moose::Meta::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('coerce' => ( - reader => 'coerce', - predicate => { - 'has_coercion' => sub { $_[0]->coerce() ? 1 : 0 } - } - )) -); - -Moose::Meta::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('weak_ref' => ( - reader => 'weak_ref', - predicate => { - 'has_weak_ref' => sub { $_[0]->weak_ref() ? 1 : 0 } - } - )) -); +__PACKAGE__->meta->add_attribute('coerce' => ( + reader => 'coerce', + predicate => { 'has_coercion' => sub { $_[0]->coerce() ? 1 : 0 } } +)); + +__PACKAGE__->meta->add_attribute('weak_ref' => ( + reader => 'weak_ref', + predicate => { 'has_weak_ref' => sub { $_[0]->weak_ref() ? 1 : 0 } } +)); -Moose::Meta::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('type_constraint' => ( - reader => 'type_constraint', - predicate => 'has_type_constraint', - )) -); +__PACKAGE__->meta->add_attribute('type_constraint' => ( + reader => 'type_constraint', + predicate => 'has_type_constraint', +)); -Moose::Meta::Attribute->meta->add_before_method_modifier('new' => sub { +__PACKAGE__->meta->add_before_method_modifier('new' => sub { my (undef, undef, %options) = @_; if (exists $options{coerce} && $options{coerce}) { (exists $options{type_constraint}) diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index b18e498..bb16b01 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -10,8 +10,6 @@ use Carp 'confess'; our $VERSION = '0.01'; -my %TYPE_CONSTRAINT_REGISTRY; - __PACKAGE__->meta->add_attribute('name' => (reader => 'name' )); __PACKAGE__->meta->add_attribute('parent' => (reader => 'parent' )); __PACKAGE__->meta->add_attribute('constraint' => (reader => 'constraint')); diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index cf08065..2117e0e 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -7,13 +7,10 @@ use metaclass 'Moose::Meta::Class' => ( ':attribute_metaclass' => 'Moose::Meta::Attribute' ); -use Carp 'confess'; - our $VERSION = '0.02'; sub new { - my $class = shift; - my %params = @_; + my ($class, %params) = @_; my $self = $class->meta->new_object(%params); $self->BUILDALL(%params); return $self; diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index cf99b1d..b37e824 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -24,15 +24,12 @@ sub import { { my %TYPES; - sub find_type_constraint { - my $type_name = shift; - $TYPES{$type_name}; - } + sub find_type_constraint { $TYPES{$_[0]} } - sub register_type_constraint { + sub create_type_constraint { my ($name, $parent, $constraint) = @_; (not exists $TYPES{$name}) - || confess "The type constraint '$name' has already been registered"; + || confess "The type constraint '$name' has already been created"; $parent = find_type_constraint($parent) if defined $parent; $TYPES{$name} = Moose::Meta::TypeConstraint->new( name => $name, @@ -66,13 +63,13 @@ sub import { sub type ($$) { my ($name, $check) = @_; - register_type_constraint($name, undef, $check); + create_type_constraint($name, undef, $check); } sub subtype ($$;$) { if (scalar @_ == 3) { my ($name, $parent, $check) = @_; - register_type_constraint($name, $parent, $check); + create_type_constraint($name, $parent, $check); } else { my ($parent, $check) = @_; @@ -194,7 +191,7 @@ Suggestions for improvement are welcome. =item B -=item B +=item B =item B