6 use Test::More tests => 20;
11 use_ok('Class::MOP::Attribute');
16 my $regexp = qr/hello (.*)/;
17 my $attr = Class::MOP::Attribute->new('$test' => (
21 ok($attr->has_default, '... we have a default value');
22 is($attr->default, $regexp, '... and got the value we expected');
25 { # bad construtor args
27 Class::MOP::Attribute->new();
28 } '... no name argument';
31 Class::MOP::Attribute->new('');
32 } '... bad name argument';
35 Class::MOP::Attribute->new(0);
36 } '... bad name argument';
40 my $attr = Class::MOP::Attribute->new('$test');
42 $attr->attach_to_class();
43 } '... attach_to_class died as expected';
46 $attr->attach_to_class('Fail');
47 } '... attach_to_class died as expected';
50 $attr->attach_to_class(bless {} => 'Fail');
51 } '... attach_to_class died as expected';
55 my $attr = Class::MOP::Attribute->new('$test' => (
56 reader => [ 'whoops, this wont work' ]
59 $attr->attach_to_class(Class::MOP::Class->initialize('Foo'));
62 $attr->install_accessors;
63 } '... bad reader format';
67 my $attr = Class::MOP::Attribute->new('$test');
70 $attr->process_accessors('fail', 'my_failing_sub');
71 } '... cannot find "fail" type generator';
77 package My::Attribute;
78 our @ISA = ('Class::MOP::Attribute');
79 sub generate_reader_method { eval { die } }
82 my $attr = My::Attribute->new('$test' => (
87 $attr->install_accessors;
88 } '... failed to generate accessors correctly';
92 my $attr = Class::MOP::Attribute->new('$test' => (
93 predicate => 'has_test'
96 my $Bar = Class::MOP::Class->create('Bar' => '0.01');
97 isa_ok($Bar, 'Class::MOP::Class');
99 $Bar->add_attribute($attr);
101 can_ok('Bar', 'has_test');
103 is($attr, $Bar->remove_attribute('$test'), '... removed the $test attribute');
105 ok(!Bar->can('has_test'), '... Bar no longer has the "has_test" method');
111 # the next three tests once tested that
112 # the code would fail, but we lifted the
113 # restriction so you can have an accessor
114 # along with a reader/writer pair (I mean
115 # why not really). So now they test that
116 # it works, which is kinda silly, but it
117 # tests the API change, so I keep it.
120 Class::MOP::Attribute->new('$foo', (
124 } '... can create accessors with reader/writers';
127 Class::MOP::Attribute->new('$foo', (
131 } '... can create accessors with reader/writers';
134 Class::MOP::Attribute->new('$foo', (
139 } '... can create accessors with reader/writers';