Commits

Toby Inkster  committed dc678d5

more tests

  • Participants
  • Parent commits f253f70

Comments (0)

Files changed (3)

File lib/MooX/Struct.pm

 	{
 		my ($self, $klass, $name, $val) = @_;
 		
+		confess("option '$name' unknown")
+			unless $name eq '-isa';
+		
 		my @parents = map {
 			exists $self->class_map->{$_}
 				? $self->class_map->{$_}->()
 	sub process_spec
 	{
 		my ($self, $klass, $name, $val) = @_;
-		my $accessor_type = $self->flags->{rw} ? 'rw' : 'ro';
 		
 		my %spec = (
-			is => $accessor_type,
+			is => ($self->flags->{rw} ? 'rw' : 'ro'),
 			( does($val, 'ARRAY')
 				? @$val
 				: ( does($val,'HASH') ? %$val : () )
 			$spec{isa} ||= sub { blessed($_[0]) or not ref($_[0]) };
 		}
 		
-		return \%spec;
+		return ($name, \%spec);
 	}
 	
 	sub process_attribute
 	{
-		my ($self, $klass, $name, $val) = @_;
-		
-		my $spec = $self->process_spec($klass, $name, $val);
+		my ($self, $klass, $name, $val) = @_;		
+		my $spec;
+		($name, $spec) = $self->process_spec($klass, $name, $val);
 		
 		Moo
 			->_constructor_maker_for($klass)
 }
 
 no Moo;
-
 1;
 
 __END__
     Point3D => [ -isa => ['Point'], 'z' ],
  ;
  
- my $origin = Point3D->new(x => 0, y => 0, z => 0);
+ my $origin = Point3D->new( x => 0, y => 0, z => 0 );
 
 =head1 DESCRIPTION
 

File t/05methods.t

+use Test::More tests => 1;
+use MooX::Struct
+	Person => [
+		qw( name age sex ),
+		uc_name => sub {
+			my $self = shift;
+			return uc $self->name;
+		},
+	];
+
+is(Person->new(name => 'Bob')->uc_name, 'BOB');

File t/06sigils.t

+use Test::More skip_all => 'undocumented feature; not fully working';
+use MooX::Struct Structure => [qw( $value %dict @list )];
+
+ok eval {
+	Structure->new( value => Structure->new )
+};
+
+ok eval {
+	Structure->new( value => 42 )
+};
+
+ok eval {
+	Structure->new( list => [] )
+};
+
+ok eval {
+	Structure->new( dict => +{} )
+};
+
+ok !eval {
+	Structure->new( value => [] )
+};
+
+ok !eval {
+	Structure->new( value => +{} )
+};
+
+ok !eval {
+	Structure->new( list => 42 )
+};
+
+ok !eval {
+	Structure->new( dict => 42 )
+};
+
+done_testing();