2 # Moose compatible methods/functions
4 use Test::Builder (); # should load Test::Builder first
7 use Mouse::Util::MetaRole;
8 use Mouse::Meta::Method;
9 use Mouse::Meta::Role::Method;
11 $INC{'Mouse/Meta.pm'} = __FILE__;
12 $INC{'Mouse/Meta/Instance.pm'} = __FILE__;
13 $INC{'Mouse/Deprecated.pm'} = __FILE__;
15 *UNIVERSAL::DOES = sub {
16 my($thing, $role) = @_;
18 } unless UNIVERSAL->can('DOES');
20 $Mouse::Deprecated::deprecated = $Mouse::Deprecated::deprecated = undef; # -w
24 sub resolve_metatrait_alias {
25 return resolve_metaclass_alias( @_, trait => 1);
28 sub ensure_all_roles {
30 apply_all_roles($consumer, grep { !does_role($appicant, $_) } @_);
34 package Mouse::Meta::Module;
36 sub version { no strict 'refs'; ${shift->name.'::VERSION'} }
37 sub authority { no strict 'refs'; ${shift->name.'::AUTHORITY'} }
42 ($self->version || ()),
43 ($self->authority || ()),
47 sub role_applications { }
49 package Mouse::Meta::Role;
51 for my $modifier_type (qw/before after around/) {
52 my $modifier = "${modifier_type}_method_modifiers";
53 my $has_method_modifiers = sub{
54 my($self, $method_name) = @_;
55 my $m = $self->{$modifier}->{$method_name};
56 return $m && @{$m} != 0;
60 *{ 'has_' . $modifier_type . '_method_modifiers' } = $has_method_modifiers;
64 sub has_override_method_modifier {
65 my ($self, $method_name) = @_;
66 return exists $self->{override_method_modifiers}->{$method_name};
69 sub get_method_modifier_list {
70 my($self, $modifier_type) = @_;
72 return keys %{ $self->{$modifier_type . '_method_modifiers'} };
75 package Mouse::Meta::Method;
77 sub get_original_method { Mouse::Meta::Method->wrap(sub { }) }
79 sub associated_attribute { undef }
81 package Mouse::Util::TypeConstraints;
83 use Mouse::Util::TypeConstraints ();
85 sub export_type_constraints_as_functions { # TEST ONLY
88 foreach my $type( list_all_type_constraints() ) {
89 my $tc = find_type_constraint($type)->_compiled_type_constraint;
90 my $as = $into . '::' . $type;
93 *{$as} = sub{ &{$tc} || undef };
98 package Mouse::Meta::Attribute;
100 sub applied_traits{ $_[0]->{traits} } # TEST ONLY
101 sub has_applied_traits{ exists $_[0]->{traits} } # TEST ONLY
103 sub get_raw_value { undef } # not supported
104 sub set_raw_value { undef } # not supported
106 package Mouse::Meta::TypeConstraint;
108 sub has_message { exists $_[0]->{message} }
111 my($self, $value) = @_;
112 return $self->check($value) ? undef : $self->get_message($value);
116 my($self, $other) = @_;
117 return undef; # not supported
121 my($self, $other) = @_;
122 return undef; # not supported