Commits

Toby Inkster committed e07ec41

change interaction between roles/FIELDS/BUILDARGS/etc

  • Participants
  • Parent commits 1a026c4

Comments (0)

Files changed (3)

lib/MooX/Struct.pm

 
 BEGIN {
 	$MooX::Struct::AUTHORITY = 'cpan:TOBYINK';
-	$MooX::Struct::VERSION   = '0.009';
+	$MooX::Struct::VERSION   = '0.008';
 }
 
 use Moo          1.000000;
 	
 	my $hashref = $class->SUPER::BUILDARGS(@_);
 	
-	my %tmp = map { $_ => 1 } keys %$hashref;
-	delete $tmp{$_} for @fields;
-	if (my @unknown = sort keys %tmp)
-	{
-		Carp::confess("unknown keys passed to constructor (@unknown); stopped");
-	}
+#	my %tmp = map { $_ => 1 } keys %$hashref;
+#	delete $tmp{$_} for @fields;
+#	if (my @unknown = sort keys %tmp)
+#	{
+#		Carp::confess("unknown keys passed to constructor (@unknown); stopped");
+#	}
 	
 	return $hashref;
 }
 	{
 		no warnings;
 		our $AUTHORITY = 'cpan:TOBYINK';
-		our $VERSION   = '0.009';
+		our $VERSION   = '0.008';
 	}
 	
 	sub _uniq { my %seen; grep { not $seen{$_}++ } @_ };
 			last;
 		}
 		$klass ||= sprintf('%s::__ANON__::%04d', $self->base, ++$counter);
-		Moo->_set_superclasses($klass, $self->base);
-		Moo->_maybe_reset_handlemoose($klass);
+		"Moo"->_set_superclasses($klass, $self->base);
+		"Moo"->_maybe_reset_handlemoose($klass);
 		if ($self->trace)
 		{
 			$self->trace_handle->printf(
 					? $self->class_map->{$_}->()
 					: $_
 			} @$val;
-			Moo->_set_superclasses($klass, @parents);
-			Moo->_maybe_reset_handlemoose($klass);
+			"Moo"->_set_superclasses($klass, @parents);
+			"Moo"->_maybe_reset_handlemoose($klass);
 			
 			if ($self->trace)
 			{
 		elsif ($name eq '-with')
 		{
 			require Moo::Role;
-			Moo::Role->apply_roles_to_package($klass, @$val);
-			Moo->_maybe_reset_handlemoose($klass);
+			"Moo::Role"->apply_roles_to_package($klass, @$val);
+			"Moo"->_maybe_reset_handlemoose($klass);
 			
 			if ($self->trace)
 			{
 				);
 			}
 			
-			return map {
-				my $role = $_;
-				grep { not ref $_ } @{ $Moo::Role::INFO{$role}{attributes} }
-			} @$val;
+			return
+			#	map  { my $role = $_; grep { not ref $_ } @{ $Moo::Role::INFO{$role}{attributes} } }
+			#	@$val;
 		}
 		elsif ($name eq '-class')
 		{
 			if ($self->flags->{deparse})
 			{
 				require B::Deparse;
-				my $code = B::Deparse->new(qw(-q -si8T))->coderef2text($coderef);
+				my $code = "B::Deparse"->new(qw(-q -si8T))->coderef2text($coderef);
 				$code =~ s/^/# /mig;
 				$self->trace_handle->printf("$code\n");
 			}
 		if ($self->trace)
 		{
 			require Data::Dumper;
-			my $spec_str = Data::Dumper->new([$spec])->Terse(1)->Indent(0)->Dump;
+			my $spec_str = "Data::Dumper"->new([$spec])->Terse(1)->Indent(0)->Dump;
 			$spec_str =~ s/(^\{)|(\}$)//g;
 			$self->trace_handle->printf(
 				"has %s => (%s);\n",
 			if ($self->flags->{deparse} and $spec->{isa})
 			{
 				require B::Deparse;
-				my $code = B::Deparse->new(qw(-q -si8T))->coderef2text($spec->{isa});
+				my $code = "B::Deparse"->new(qw(-q -si8T))->coderef2text($spec->{isa});
 				$code =~ s/^/# /mig;
 				$self->trace_handle->printf("$code\n");
 			}
 		}
 		
-		Moo
+		"Moo"
 			->_constructor_maker_for($klass)
 			->register_attribute_specs($name, $spec);
 			
-		Moo
+		"Moo"
 			->_accessor_maker_for($klass)
 			->generate_method($klass, $name, $spec);
 			
-		Moo
+		"Moo"
 			->_maybe_reset_handlemoose($klass);
 		
 		return $name;
 				my $klass  = $self->create_class($opts);
 				my $seen_extends;
 				my @fields = _uniq map {
-					++$seen_extends if $_->[0] =~ /^-(?:extends|isa)$/;
+					++$seen_extends if $_->[0] eq '-extends';
 					$self->process_argument($klass, @$_);
 				} @$opts;
 				unshift @fields, $self->base->FIELDS
 The order the fields are returned in is equal to the order they must be supplied
 for the positional constructor.
 
+Attributes inherited from roles, or from non-struct base classes are not included
+in C<FIELDS>, and thus cannot be used in the positional constructor.
+
 =item C<TYPE>
 
 Returns the type name of the struct, e.g. C<< 'Point3D' >>.
 
 is_deeply(
 	[ Thingy->FIELDS ],
-	[ qw/ attr2 attr1 attr3 attr4 / ],
+	[ qw/ attr3 attr4 / ],
 );
 
-my $thingy = Thingy[qw/ 2 1 3 4 /];
+my $thingy = Thingy[qw/ 3 4 /];
+#is($thingy->attr1, 1);
+#is($thingy->attr2, 2);
+is($thingy->attr3, 3);
+is($thingy->attr4, 4);
+
+$thingy = Thingy->new(map { ; "attr$_", $_ } 1..4);
 is($thingy->attr1, 1);
 is($thingy->attr2, 2);
 is($thingy->attr3, 3);

t/10strict-constructor.t

 Check that the constructor is strict (throws an error if it sees unknown
 attributes).
 
+This test is currently disabled, as the constructor is no longer strict.
+
 =head1 AUTHOR
 
 Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
 
 =cut
 
-use Test::More tests => 1;
+use Test::More skip_all => 'no longer valid';
 use MooX::Struct Thingy => [qw/ $x /];
 
 ok not eval { my $thingy = Thingy->new(y => 1) };