9 use Moose::Util 'does_role', 'find_meta';
11 our $VERSION = '0.56';
12 our $AUTHORITY = 'cpan:STEVAN';
20 Sub::Exporter::setup_exporter({
22 groups => { default => \@exports }
25 ## the test builder instance ...
27 my $Test = Test::Builder->new;
32 my ($class_or_obj, $message) = @_;
34 $message ||= "The object has a meta";
36 if (find_meta($class_or_obj)) {
37 return $Test->ok(1, $message)
40 return $Test->ok(0, $message);
45 my ($class_or_obj, $does, $message) = @_;
47 $message ||= "The object does $does";
49 if (does_role($class_or_obj, $does)) {
50 return $Test->ok(1, $message)
53 return $Test->ok(0, $message);
57 sub has_attribute_ok ($$;$) {
58 my ($class_or_obj, $attr_name, $message) = @_;
60 $message ||= "The object does has an attribute named $attr_name";
62 my $meta = find_meta($class_or_obj);
64 if ($meta->find_attribute_by_name($attr_name)) {
65 return $Test->ok(1, $message)
68 return $Test->ok(0, $message);
80 Test::Moose - Test functions for Moose specific features
84 use Test::More plan => 1;
87 meta_ok($class_or_obj, "... Foo has a ->meta");
88 does_ok($class_or_obj, $role, "... Foo does the Baz role");
89 has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute");
93 This module provides some useful test functions for Moose based classes. It
94 is an experimental first release, so comments and suggestions are very welcome.
96 =head1 EXPORTED FUNCTIONS
100 =item B<meta_ok ($class_or_object)>
102 Tests if a class or object has a metaclass.
104 =item B<does_ok ($class_or_object, $role, ?$message)>
106 Tests if a class or object does a certain role, similar to what C<isa_ok>
107 does for the C<isa> method.
109 =item B<has_attribute_ok($class_or_object, $attr_name, ?$message)>
111 Tests if a class or object has a certain attribute, similar to what C<can_ok>
112 does for the methods.
120 =item Convert the Moose test suite to use this module.
122 =item Here is a list of possible functions to write
126 =item immutability predicates
128 =item anon-class predicates
130 =item discovering original method from modified method
132 =item attribute metaclass predicates (attribute_isa?)
148 All complex software has bugs lurking in it, and this module is no
149 exception. If you find a bug please either email me, or add the bug
154 Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
156 Stevan Little E<lt>stevan@iinteractive.comE<gt>
158 =head1 COPYRIGHT AND LICENSE
160 Copyright 2007-2008 by Infinity Interactive, Inc.
162 L<http://www.iinteractive.com>
164 This library is free software; you can redistribute it and/or modify
165 it under the same terms as Perl itself.