8 use Moose::Util 'does_role', 'find_meta';
10 our $VERSION = '0.01';
11 our $AUTHORITY = 'cpan:STEVAN';
19 Sub::Exporter::setup_exporter({
21 groups => { default => \@exports }
24 ## the test builder instance ...
26 my $Test = Test::Builder->new;
31 my ($class_or_obj, $message) = @_;
33 $message ||= "The object has a meta";
35 if (find_meta($class_or_obj)) {
36 return $Test->ok(1, $message)
39 return $Test->ok(0, $message);
44 my ($class_or_obj, $does, $message) = @_;
46 $message ||= "The object does $does";
48 if (does_role($class_or_obj, $does)) {
49 return $Test->ok(1, $message)
52 return $Test->ok(0, $message);
56 sub has_attribute_ok ($$;$) {
57 my ($class_or_obj, $attr_name, $message) = @_;
59 $message ||= "The object does has an attribute named $attr_name";
61 my $meta = find_meta($class_or_obj);
63 if ($meta->find_attribute_by_name($attr_name)) {
64 return $Test->ok(1, $message)
67 return $Test->ok(0, $message);
79 Test::Moose - Test functions for Moose specific features
83 use Test::More plan => 1;
86 meta_ok($class_or_obj, "... Foo has a ->meta");
87 does_ok($class_or_obj, $role, "... Foo does the Baz role");
88 has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute");
92 This module provides some useful test functions for Moose based classes. It
93 is an experimental first release, so comments and suggestions are very welcome.
95 =head1 EXPORTED FUNCTIONS
99 =item B<meta_ok ($class_or_object)>
101 Tests if a class or object has a metaclass.
103 =item B<does_ok ($class_or_object, $role, ?$message)>
105 Tests if a class or object does a certain role, similar to what C<isa_ok>
106 does for the C<isa> method.
108 =item B<has_attribute_ok($class_or_object, $attr_name, ?$message)>
110 Tests if a class or object has a certain attribute, similar to what C<can_ok>
111 does for the methods.
119 =item Convert the Moose test suite to use this module.
121 =item Here is a list of possible functions to write
125 =item immutability predicates
127 =item anon-class predicates
129 =item discovering original method from modified method
131 =item attribute metaclass predicates (attribute_isa?)
147 All complex software has bugs lurking in it, and this module is no
148 exception. If you find a bug please either email me, or add the bug
153 Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
155 Stevan Little E<lt>stevan@iinteractive.comE<gt>
157 =head1 COPYRIGHT AND LICENSE
159 Copyright 2007 by Infinity Interactive, Inc.
161 L<http://www.iinteractive.com>
163 This library is free software; you can redistribute it and/or modify
164 it under the same terms as Perl itself.