9 use Moose::Util 'does_role', 'find_meta';
11 our $VERSION = '0.93';
12 $VERSION = eval $VERSION;
13 our $AUTHORITY = 'cpan:STEVAN';
22 Sub::Exporter::setup_exporter({
24 groups => { default => \@exports }
27 ## the test builder instance ...
29 my $Test = Test::Builder->new;
34 my ($class_or_obj, $message) = @_;
36 $message ||= "The object has a meta";
38 if (find_meta($class_or_obj)) {
39 return $Test->ok(1, $message)
42 return $Test->ok(0, $message);
47 my ($class_or_obj, $does, $message) = @_;
49 $message ||= "The object does $does";
51 if (does_role($class_or_obj, $does)) {
52 return $Test->ok(1, $message)
55 return $Test->ok(0, $message);
59 sub has_attribute_ok ($$;$) {
60 my ($class_or_obj, $attr_name, $message) = @_;
62 $message ||= "The object does has an attribute named $attr_name";
64 my $meta = find_meta($class_or_obj);
66 if ($meta->find_attribute_by_name($attr_name)) {
67 return $Test->ok(1, $message)
70 return $Test->ok(0, $message);
74 sub with_immutable (&@) {
77 $_->meta->make_immutable for @_;
89 Test::Moose - Test functions for Moose specific features
93 use Test::More plan => 1;
96 meta_ok($class_or_obj, "... Foo has a ->meta");
97 does_ok($class_or_obj, $role, "... Foo does the Baz role");
98 has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute");
102 This module provides some useful test functions for Moose based classes. It
103 is an experimental first release, so comments and suggestions are very welcome.
105 =head1 EXPORTED FUNCTIONS
109 =item B<meta_ok ($class_or_object)>
111 Tests if a class or object has a metaclass.
113 =item B<does_ok ($class_or_object, $role, ?$message)>
115 Tests if a class or object does a certain role, similar to what C<isa_ok>
116 does for the C<isa> method.
118 =item B<has_attribute_ok($class_or_object, $attr_name, ?$message)>
120 Tests if a class or object has a certain attribute, similar to what C<can_ok>
121 does for the methods.
129 =item Convert the Moose test suite to use this module.
131 =item Here is a list of possible functions to write
135 =item immutability predicates
137 =item anon-class predicates
139 =item discovering original method from modified method
141 =item attribute metaclass predicates (attribute_isa?)
157 All complex software has bugs lurking in it, and this module is no
158 exception. If you find a bug please either email me, or add the bug
163 Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
165 Stevan Little E<lt>stevan@iinteractive.comE<gt>
167 =head1 COPYRIGHT AND LICENSE
169 Copyright 2007-2009 by Infinity Interactive, Inc.
171 L<http://www.iinteractive.com>
173 This library is free software; you can redistribute it and/or modify
174 it under the same terms as Perl itself.