Support modifier by regexp
[gitmo/Mouse.git] / t / lib / MooseCompat.pm
CommitLineData
73e9153a 1package MooseCompat;
2# Moose compatible methods/functions
3
4package Mouse::Meta::Module;
5
6sub version { no strict 'refs'; ${shift->name.'::VERSION'} }
7sub authority { no strict 'refs'; ${shift->name.'::AUTHORITY'} }
8sub identifier {
9 my $self = shift;
10 return join '-' => (
11 $self->name,
12 ($self->version || ()),
13 ($self->authority || ()),
14 );
15}
16
17package Mouse::Meta::Role;
18
19for my $modifier_type (qw/before after around/) {
20 my $modifier = "${modifier_type}_method_modifiers";
21 my $has_method_modifiers = sub{
22 my($self, $method_name) = @_;
23 my $m = $self->{$modifier}->{$method_name};
24 return $m && @{$m} != 0;
25 };
26
27 no strict 'refs';
28 *{ 'has_' . $modifier_type . '_method_modifiers' } = $has_method_modifiers;
29}
30
31
32sub has_override_method_modifier {
33 my ($self, $method_name) = @_;
34 return exists $self->{override_method_modifiers}->{$method_name};
35}
36
37sub get_method_modifier_list {
38 my($self, $modifier_type) = @_;
39
40 return keys %{ $self->{$modifier_type . '_method_modifiers'} };
41}
42
43package Mouse::Util::TypeConstraints;
44
45use Mouse::Util::TypeConstraints ();
46
47sub export_type_constraints_as_functions { # TEST ONLY
48 my $into = caller;
49
50 foreach my $type( list_all_type_constraints() ) {
51 my $tc = find_type_constraint($type)->_compiled_type_constraint;
52 my $as = $into . '::' . $type;
53
54 no strict 'refs';
55 *{$as} = sub{ &{$tc} || undef };
56 }
57 return;
58}
59
60package
61 Mouse::Meta::Attribute;
62
63sub applied_traits{ $_[0]->{traits} } # TEST ONLY
64sub has_applied_traits{ exists $_[0]->{traits} } # TEST ONLY
65
661;