10 plan skip_all => "no XSLoader" unless eval { require XSLoader };
12 plan skip_all => $@ unless eval {
14 Moose->XSLoader::load($Moose::VERSION);
24 sub attr_to_meta_instance {
26 return $attr->associated_class->get_meta_instance;
30 my %checks = map { $_ => $i++ } qw(
50 $checks{Bool} = $checks{Item} = $checks{Any};
51 $checks{Value} = $checks{Str};
56 return ( undef, 0, undef ) unless $tc;
58 if ( ref $tc eq 'Moose::Meta::TypeConstraint' or ref $tc eq 'Moose::Meta::TypeConstraint::Parameterizable') {
59 # builtin moose type #
60 return ( $tc, 1, $checks{$tc->name} );
61 } elsif ( $tc->isa("Moose::Meta::TypeConstraint::Class") ) {
62 return ( $tc, 2, $tc->class );
65 return ( $tc, 3, $tc->_compiled_type_constraint );
69 sub meta_instance_to_attr_descs {
73 $mi->associated_metaclass->name,
82 tc_params($_->type_constraint),
89 ]} $mi->get_all_attributes ]
94 ok( defined &Moose::XS::new_getter );
95 ok( defined &Moose::XS::new_setter );
96 ok( defined &Moose::XS::new_accessor );
97 ok( defined &Moose::XS::new_predicate );
103 has x => ( is => "rw", predicate => "has_x" );
104 has y => ( is => "ro" );
105 has z => ( reader => "z", setter => "set_z" );
106 has ref => ( is => "rw", weak_ref => 1 );
107 has i => ( isa => "Int", is => "rw" );
108 has s => ( isa => "Str", is => "rw" );
109 has a => ( isa => "ArrayRef", is => "rw" );
111 # FIXME Regexp, Class, ClassName, Object, parametrized, filehandle
115 my ( $x, $y, $z, $ref, $a, $s, $i ) = map { Foo->meta->get_attribute($_) } qw(x y z ref a s i);
116 $x->Moose::XS::new_accessor("Foo::x");
117 $x->Moose::XS::new_predicate("Foo::has_x");
118 $y->Moose::XS::new_getter("Foo::y");
119 $z->Moose::XS::new_getter("Foo::z");
120 $z->Moose::XS::new_setter("Foo::set_z");
121 $ref->Moose::XS::new_accessor("Foo::ref");
122 $a->Moose::XS::new_accessor("Foo::a");
123 $s->Moose::XS::new_accessor("Foo::s");
124 $i->Moose::XS::new_accessor("Foo::i");
130 my $foo = Foo->new( x => "ICKS", y => "WHY", z => "ZEE", ref => $ref );
132 is( $foo->x, "ICKS" );
133 is( $foo->y, "WHY" );
134 is( $foo->z, "ZEE" );
135 is( $foo->ref, $ref, );
137 lives_ok { $foo->x("YASE") };
139 is( $foo->x, "YASE" );
141 dies_ok { $foo->y("blah") };
143 is( $foo->y, "WHY" );
145 dies_ok { $foo->z("blah") };
147 is( $foo->z, "ZEE" );
149 lives_ok { $foo->set_z("new") };
151 is( $foo->z, "new" );
155 ok( !Foo->new->has_x );
159 is( $foo->ref(), undef );
165 is( $foo->ref, $ref, );
169 is( $foo->ref(), undef );
171 ok( !eval { $foo->a("not a ref"); 1 } );
172 ok( !eval { $foo->i(1.3); 1 } );
173 ok( !eval { $foo->s(undef); 1 } );
175 ok( eval { $foo->a([]); 1 } );
176 ok( eval { $foo->i(3); 1 } );
177 ok( eval { $foo->s("foo"); 1 } );