From: Stevan Little Date: Tue, 11 Dec 2007 15:26:58 +0000 (+0000) Subject: foo X-Git-Tag: 0_33~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=97e11ef507470a5854419d6edffd2b1e8f8118c3;p=gitmo%2FMoose.git foo --- diff --git a/Changes b/Changes index 5632683..41773fc 100644 --- a/Changes +++ b/Changes @@ -4,8 +4,11 @@ Revision history for Perl extension Moose * Moose::Meta::TypeConstraint::Parameterized - allow subtypes of ArrayRef and HashRef to be used as a container (sartak) + - added tests for this - basic support for coercion to ArrayRef and HashRef for containers (sartak) + - added tests for this + * Moose::Meta::Method::Accessor - allow subclasses to decide whether we need to copy the value into a new variable (sartak) diff --git a/MANIFEST b/MANIFEST index f4baebd..06a32cb 100644 --- a/MANIFEST +++ b/MANIFEST @@ -109,6 +109,8 @@ t/040_type_constraints/014_type_notation_parser.t t/040_type_constraints/015_enum.t t/040_type_constraints/016_subtyping_parameterized_types.t t/040_type_constraints/017_subtyping_union_types.t +t/040_type_constraints/018_custom_parameterized_types.t +t/040_type_constraints/019_coerced_parameterized_types.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 diff --git a/README b/README index 4f434c9..e6c4f20 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Moose version 0.32 +Moose version 0.33 =========================== See the individual module documentation for more information diff --git a/lib/Moose.pm b/lib/Moose.pm index d4d7e46..cf44a30 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -4,7 +4,7 @@ package Moose; use strict; use warnings; -our $VERSION = '0.32'; +our $VERSION = '0.33'; our $AUTHORITY = 'cpan:STEVAN'; use Scalar::Util 'blessed', 'reftype'; @@ -36,12 +36,12 @@ use Moose::Util::TypeConstraints; $metaclass = 'Moose::Meta::Class' unless defined $metaclass; confess - "The Metaclass $metaclass must be a subclass of Moose::Meta::Class." - unless $metaclass->isa('Moose::Meta::Class'); + "The Metaclass $metaclass must be a subclass of Moose::Meta::Class." + unless $metaclass->isa('Moose::Meta::Class'); # make a subtype for each Moose class subtype $class => as 'Object' => where { $_->isa($class) } => - optimize_as { blessed( $_[0] ) && $_[0]->isa($class) } + optimize_as { blessed( $_[0] ) && $_[0]->isa($class) } unless find_type_constraint($class); my $meta; diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 0e0987d..4b7a451 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -122,16 +122,16 @@ sub _inline_pre_body { '' } sub _inline_post_body { '' } sub _inline_check_constraint { - my ($self, $value) = @_; - - my $attr = $self->associated_attribute; - - return '' unless $attr->has_type_constraint; - - # FIXME - # This sprintf is insanely annoying, we should - # fix it someday - SL - return sprintf <<'EOF', $value, $value, $value, $value, $value, $value, $value + my ($self, $value) = @_; + + my $attr = $self->associated_attribute; + + return '' unless $attr->has_type_constraint; + + # FIXME + # This sprintf is insanely annoying, we should + # fix it someday - SL + return sprintf <<'EOF', $value, $value, $value, $value, $value, $value, $value defined($type_constraint->(%s)) || confess "Attribute (" . $attr->name . ") does not pass the type constraint (" . $attr->type_constraint->name . ") with " @@ -141,16 +141,16 @@ EOF } sub _inline_check_coercion { - my $attr = (shift)->associated_attribute; - - return '' unless $attr->should_coerce; + my $attr = (shift)->associated_attribute; + + return '' unless $attr->should_coerce; return '$val = $attr->type_constraint->coerce($_[1]);' } sub _inline_check_required { - my $attr = (shift)->associated_attribute; - - return '' unless $attr->is_required; + my $attr = (shift)->associated_attribute; + + return '' unless $attr->is_required; return 'defined($_[1]) || confess "Attribute ($attr_name) is required, so cannot be set to undef";' } @@ -167,10 +167,11 @@ sub _inline_check_lazy { my $code = 'unless (' . $slot_exists . ') {' . "\n"; if ($attr->has_type_constraint) { - if($attr->has_default || $attr->has_builder){ - if($attr->has_default){ + if ($attr->has_default || $attr->has_builder) { + if ($attr->has_default) { $code .= ' my $default = $attr->default(' . $inv . ');'."\n"; - } elsif($attr->has_builder){ + } + elsif ($attr->has_builder) { $code .= ' my $default;'."\n". ' if(my $builder = '.$inv.'->can($attr->builder)){ '."\n". ' $default = '.$inv.'->$builder; '. "\n } else {\n" . @@ -183,19 +184,22 @@ sub _inline_check_lazy { ' . $attr->type_constraint->name . ") with " . (defined($default) ? (Scalar::Util::blessed($default) && overload::Overloaded($default) ? overload::StrVal($default) : $default) : "undef")' . ' if defined($default);' . "\n" . ' ' . $slot_access . ' = $default; ' . "\n"; - } else { + } + else { $code .= ' ' . $slot_access . " = undef; \n"; } } else { - if($attr->has_default){ + if ($attr->has_default) { $code .= ' '.$slot_access.' = $attr->default(' . $inv . ');'."\n"; - } elsif($attr->has_builder){ + } + elsif ($attr->has_builder) { $code .= ' if(my $builder = '.$inv.'->can($attr->builder)){ '."\n". ' '.$slot_access.' = '.$inv.'->$builder; '. "\n } else {\n" . ' confess(Scalar::Util::blessed('.$inv.')." does not support builder method '. '\'".$attr->builder."\' for attribute \'" . $attr->name . "\'");'. "\n }"; - } else { + } + else { $code .= ' ' . $slot_access . " = undef; \n"; } } @@ -205,51 +209,51 @@ sub _inline_check_lazy { sub _inline_store { - my ($self, $instance, $value) = @_; - my $attr = $self->associated_attribute; - - my $mi = $attr->associated_class->get_meta_instance; - my $slot_name = sprintf "'%s'", $attr->slots; - + my ($self, $instance, $value) = @_; + my $attr = $self->associated_attribute; + + my $mi = $attr->associated_class->get_meta_instance; + my $slot_name = sprintf "'%s'", $attr->slots; + my $code = $mi->inline_set_slot_value($instance, $slot_name, $value) . ";"; - $code .= $mi->inline_weaken_slot_value($instance, $slot_name, $value) . ";" - if $attr->is_weak_ref; + $code .= $mi->inline_weaken_slot_value($instance, $slot_name, $value) . ";" + if $attr->is_weak_ref; return $code; } sub _inline_trigger { - my ($self, $instance, $value) = @_; - my $attr = $self->associated_attribute; - return '' unless $attr->has_trigger; - return sprintf('$attr->trigger->(%s, %s, $attr);', $instance, $value); + my ($self, $instance, $value) = @_; + my $attr = $self->associated_attribute; + return '' unless $attr->has_trigger; + return sprintf('$attr->trigger->(%s, %s, $attr);', $instance, $value); } sub _inline_get { - my ($self, $instance) = @_; - my $attr = $self->associated_attribute; - - my $mi = $attr->associated_class->get_meta_instance; - my $slot_name = sprintf "'%s'", $attr->slots; + my ($self, $instance) = @_; + my $attr = $self->associated_attribute; + + my $mi = $attr->associated_class->get_meta_instance; + my $slot_name = sprintf "'%s'", $attr->slots; return $mi->inline_get_slot_value($instance, $slot_name); } sub _inline_access { - my ($self, $instance) = @_; - my $attr = $self->associated_attribute; - - my $mi = $attr->associated_class->get_meta_instance; - my $slot_name = sprintf "'%s'", $attr->slots; + my ($self, $instance) = @_; + my $attr = $self->associated_attribute; + + my $mi = $attr->associated_class->get_meta_instance; + my $slot_name = sprintf "'%s'", $attr->slots; return $mi->inline_slot_access($instance, $slot_name); } sub _inline_has { - my ($self, $instance) = @_; - my $attr = $self->associated_attribute; - - my $mi = $attr->associated_class->get_meta_instance; - my $slot_name = sprintf "'%s'", $attr->slots; + my ($self, $instance) = @_; + my $attr = $self->associated_attribute; + + my $mi = $attr->associated_class->get_meta_instance; + my $slot_name = sprintf "'%s'", $attr->slots; return $mi->inline_is_slot_initialized($instance, $slot_name); } diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index ae65438..c0c9671 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -124,7 +124,7 @@ sub _generate_slot_initializer { push @source => ('my $val = $params{\'' . $attr->init_arg . '\'};'); if ($is_moose && $attr->has_type_constraint) { push @source => ('my $type_constraint = $attrs->[' . $index . ']->type_constraint;'); - + if ($attr->should_coerce && $attr->type_constraint->has_coercion) { push @source => $self->_generate_type_coercion($attr, '$type_constraint', '$val', '$val'); } @@ -132,13 +132,13 @@ sub _generate_slot_initializer { } push @source => $self->_generate_slot_assignment($attr, '$val'); - push @source => "} else {"; my $default; - if( $attr->has_default ){ + if ( $attr->has_default ) { $default = $self->_generate_default_value($attr, $index); - } else { + } + else { my $builder = $attr->builder; $default = '$instance->' . $builder; }