9 use Moose::Util 'does_role', 'find_meta';
11 our $VERSION = '0.57';
12 $VERSION = eval $VERSION;
13 our $AUTHORITY = 'cpan:STEVAN';
21 Sub::Exporter::setup_exporter({
23 groups => { default => \@exports }
26 ## the test builder instance ...
28 my $Test = Test::Builder->new;
33 my ($class_or_obj, $message) = @_;
35 $message ||= "The object has a meta";
37 if (find_meta($class_or_obj)) {
38 return $Test->ok(1, $message)
41 return $Test->ok(0, $message);
46 my ($class_or_obj, $does, $message) = @_;
48 $message ||= "The object does $does";
50 if (does_role($class_or_obj, $does)) {
51 return $Test->ok(1, $message)
54 return $Test->ok(0, $message);
58 sub has_attribute_ok ($$;$) {
59 my ($class_or_obj, $attr_name, $message) = @_;
61 $message ||= "The object does has an attribute named $attr_name";
63 my $meta = find_meta($class_or_obj);
65 if ($meta->find_attribute_by_name($attr_name)) {
66 return $Test->ok(1, $message)
69 return $Test->ok(0, $message);
81 Test::Moose - Test functions for Moose specific features
85 use Test::More plan => 1;
88 meta_ok($class_or_obj, "... Foo has a ->meta");
89 does_ok($class_or_obj, $role, "... Foo does the Baz role");
90 has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute");
94 This module provides some useful test functions for Moose based classes. It
95 is an experimental first release, so comments and suggestions are very welcome.
97 =head1 EXPORTED FUNCTIONS
101 =item B<meta_ok ($class_or_object)>
103 Tests if a class or object has a metaclass.
105 =item B<does_ok ($class_or_object, $role, ?$message)>
107 Tests if a class or object does a certain role, similar to what C<isa_ok>
108 does for the C<isa> method.
110 =item B<has_attribute_ok($class_or_object, $attr_name, ?$message)>
112 Tests if a class or object has a certain attribute, similar to what C<can_ok>
113 does for the methods.
121 =item Convert the Moose test suite to use this module.
123 =item Here is a list of possible functions to write
127 =item immutability predicates
129 =item anon-class predicates
131 =item discovering original method from modified method
133 =item attribute metaclass predicates (attribute_isa?)
149 All complex software has bugs lurking in it, and this module is no
150 exception. If you find a bug please either email me, or add the bug
155 Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
157 Stevan Little E<lt>stevan@iinteractive.comE<gt>
159 =head1 COPYRIGHT AND LICENSE
161 Copyright 2007-2008 by Infinity Interactive, Inc.
163 L<http://www.iinteractive.com>
165 This library is free software; you can redistribute it and/or modify
166 it under the same terms as Perl itself.