6 use Mouse::Util qw(find_meta does_role);
8 use base qw(Test::Builder::Module);
10 our @EXPORT = qw(meta_ok does_ok has_attribute_ok);
13 my ($class_or_obj, $message) = @_;
15 $message ||= "The object has a meta";
17 if (find_meta($class_or_obj)) {
18 return __PACKAGE__->builder->ok(1, $message)
21 return __PACKAGE__->builder->ok(0, $message);
26 my ($class_or_obj, $does, $message) = @_;
29 croak "You must pass a role name";
31 $message ||= "The object does $does";
33 if (does_role($class_or_obj, $does)) {
34 return __PACKAGE__->builder->ok(1, $message)
37 return __PACKAGE__->builder->ok(0, $message);
41 sub has_attribute_ok ($$;$) {
42 my ($class_or_obj, $attr_name, $message) = @_;
44 $message ||= "The object does has an attribute named $attr_name";
46 my $meta = find_meta($class_or_obj);
48 if ($meta->find_attribute_by_name($attr_name)) {
49 return __PACKAGE__->builder->ok(1, $message)
52 return __PACKAGE__->builder->ok(0, $message);
56 # Moose compatible methods/functions
61 sub version { no strict 'refs'; ${shift->name.'::VERSION'} }
62 sub authority { no strict 'refs'; ${shift->name.'::AUTHORITY'} }
67 ($self->version || ()),
68 ($self->authority || ()),
75 for my $modifier_type (qw/before after around/) {
76 my $modifier = "${modifier_type}_method_modifiers";
77 my $has_method_modifiers = sub{
78 my($self, $method_name) = @_;
79 my $m = $self->{$modifier}->{$method_name};
80 return $m && @{$m} != 0;
84 *{ 'has_' . $modifier_type . '_method_modifiers' } = $has_method_modifiers;
88 sub has_override_method_modifier {
89 my ($self, $method_name) = @_;
90 return exists $self->{override_method_modifiers}->{$method_name};
93 sub get_method_modifier_list {
94 my($self, $modifier_type) = @_;
96 return keys %{ $self->{$modifier_type . '_method_modifiers'} };
100 Mouse::Util::TypeConstraints;
102 use Mouse::Util::TypeConstraints ();
104 sub export_type_constraints_as_functions { # TEST ONLY
107 foreach my $type( list_all_type_constraints() ) {
108 my $tc = find_type_constraint($type)->_compiled_type_constraint;
109 my $as = $into . '::' . $type;
112 *{$as} = sub{ &{$tc} || undef };
118 Mouse::Meta::Attribute;
120 sub applied_traits{ $_[0]->{traits} } # TEST ONLY
121 sub has_applied_traits{ exists $_[0]->{traits} } # TEST ONLY
131 Test::Mouse - Test functions for Mouse specific features
135 use Test::More plan => 1;
138 meta_ok($class_or_obj, "... Foo has a ->meta");
139 does_ok($class_or_obj, $role, "... Foo does the Baz role");
140 has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute");