10 our $AUTHORITY = 'cpan:STEVAN';
18 Sub::Exporter::setup_exporter({
20 groups => { default => \@exports }
23 my $Test = Test::Builder->new;
29 return Class::MOP::get_metaclass_by_name(ref($_[0]) || $_[0]);
35 my ($class_or_obj, $message) = @_;
37 $message ||= "The object has a meta";
39 if (_get_meta($class_or_obj)) {
40 return $Test->ok(1, $message)
43 return $Test->ok(0, $message);
48 my ($class_or_obj, $does, $message) = @_;
50 $message ||= "The object does $does";
52 my $meta = _get_meta($class_or_obj);
54 if ($meta->does_role($does)) {
55 return $Test->ok(1, $message)
58 return $Test->ok(0, $message);
62 sub has_attribute_ok ($$;$) {
63 my ($class_or_obj, $attr_name, $message) = @_;
65 $message ||= "The object does has an attribute named $attr_name";
67 my $meta = _get_meta($class_or_obj);
69 if ($meta->find_attribute_by_name($attr_name)) {
70 return $Test->ok(1, $message)
73 return $Test->ok(0, $message);
85 Test::Moose - Test functions for Moose specific features
89 use Test::More plan => 1;
92 meta_ok($class_or_obj, "... Foo has a ->meta");
93 does_ok($class_or_obj, $role, "... Foo does the Baz role");
94 has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute");
98 This module provides some useful test functions for Moose based classes. It
99 is an experimental first release, so comments and suggestions are very welcome.
101 =head1 EXPORTED FUNCTIONS
105 =item B<meta_ok ($class_or_object)>
107 Tests if a class or object has a metaclass.
109 =item B<does_ok ($class_or_object, $role, ?$message)>
111 Tests if a class or object does a certain role, similar to what C<isa_ok>
112 does for the C<isa> method.
114 =item B<has_attribute_ok($class_or_object, $attr_name, ?$message)>
116 Tests if a class or object has a certain attribute, similar to what C<can_ok>
117 does for the methods.
125 =item Convert the Moose test suite to use this module.
127 =item Here is a list of possible functions to write
131 =item immutability predicates
133 =item anon-class predicates
135 =item discovering original method from modified method
137 =item attribute metaclass predicates (attribute_isa?)
153 All complex software has bugs lurking in it, and this module is no
154 exception. If you find a bug please either email me, or add the bug
159 Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
161 Stevan Little E<lt>stevan@iinteractive.comE<gt>
163 =head1 COPYRIGHT AND LICENSE
165 Copyright 2007 by Infinity Interactive, Inc.
167 L<http://www.iinteractive.com>
169 This library is free software; you can redistribute it and/or modify
170 it under the same terms as Perl itself.