4 use Mouse::Util qw(does_role find_meta);
8 Mouse::Exporter->setup_import_methods(
17 ## the test builder instance ...
19 my $Test = Test::Builder->new;
24 my ($class_or_obj, $message) = @_;
26 $message ||= "The object has a meta";
28 if (find_meta($class_or_obj)) {
29 return $Test->ok(1, $message)
32 return $Test->ok(0, $message);
37 my ($class_or_obj, $does, $message) = @_;
39 $message ||= "The object does $does";
41 if (does_role($class_or_obj, $does)) {
42 return $Test->ok(1, $message)
45 return $Test->ok(0, $message);
49 sub has_attribute_ok ($$;$) {
50 my ($class_or_obj, $attr_name, $message) = @_;
52 $message ||= "The object does has an attribute named $attr_name";
54 my $meta = find_meta($class_or_obj);
56 if ($meta->find_attribute_by_name($attr_name)) {
57 return $Test->ok(1, $message)
60 return $Test->ok(0, $message);
64 sub with_immutable (&@) {
67 my $before = $Test->current_test;
70 $_->meta->make_immutable for @_;
73 my $num_tests = $Test->current_test - $before;
75 return !grep{ !$_ } ($Test->summary)[-$num_tests .. -1];
83 Test::Mouse - Test functions for Mouse specific features
87 use Test::More plan => 1;
90 meta_ok($class_or_obj, "... Foo has a ->meta");
91 does_ok($class_or_obj, $role, "... Foo does the Baz role");
92 has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute");
96 This module provides some useful test functions for Mouse based classes. It
97 is an experimental first release, so comments and suggestions are very welcome.
99 =head1 EXPORTED FUNCTIONS
103 =item B<meta_ok ($class_or_object)>
105 Tests if a class or object has a metaclass.
107 =item B<does_ok ($class_or_object, $role, ?$message)>
109 Tests if a class or object does a certain role, similar to what C<isa_ok>
110 does for the C<isa> method.
112 =item B<has_attribute_ok($class_or_object, $attr_name, ?$message)>
114 Tests if a class or object has a certain attribute, similar to what C<can_ok>
115 does for the methods.