Commits

Toby Inkster committed 614333c

make constructor strict

  • Participants
  • Parent commits 9177eed

Comments (0)

Files changed (2)

lib/MooX/Struct.pm

 	}
 	
 	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");
+	}
+	
 	return $hashref;
 }
 

t/10strict-constructor.t

+use Test::More tests => 1;
+use MooX::Struct Thingy => [qw/ $x /];
+
+ok not eval { my $thingy = Thingy->new(y => 1) };