When an attribute property is malformed (such as lazy without a default), give the...
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application.pm
CommitLineData
fb1e11d5 1package Moose::Meta::Role::Application;
2
3use strict;
4use warnings;
5use metaclass;
6
7our $VERSION = '0.01';
8our $AUTHORITY = 'cpan:STEVAN';
9
c4538447 10__PACKAGE__->meta->add_attribute('method_exclusions' => (
11 init_arg => 'excludes',
12 reader => 'get_method_exclusions',
13 default => sub { [] }
14));
15
3e19778d 16__PACKAGE__->meta->add_attribute('method_aliases' => (
17 init_arg => 'alias',
18 reader => 'get_method_aliases',
19 default => sub { {} }
20));
21
c4538447 22sub new {
23 my ($class, %params) = @_;
24
25 if (exists $params{excludes}) {
26 # I wish we had coercion here :)
27 $params{excludes} = (ref $params{excludes} eq 'ARRAY'
28 ? $params{excludes}
29 : [ $params{excludes} ]);
30 }
31
32 $class->meta->new_object(%params);
33}
34
35sub is_method_excluded {
36 my ($self, $method_name) = @_;
37 foreach (@{$self->get_method_exclusions}) {
38 return 1 if $_ eq $method_name;
39 }
40 return 0;
41}
fb1e11d5 42
3e19778d 43sub is_method_aliased {
44 my ($self, $method_name) = @_;
45 exists $self->get_method_aliases->{$method_name} ? 1 : 0
46}
47
48sub is_aliased_method {
49 my ($self, $method_name) = @_;
50 my %aliased_names = reverse %{$self->get_method_aliases};
51 exists $aliased_names{$method_name} ? 1 : 0;
52}
53
fb1e11d5 54sub apply {
1c9db35c 55 my $self = shift;
fb1e11d5 56
1c9db35c 57 $self->check_role_exclusions(@_);
58 $self->check_required_methods(@_);
709c321c 59 $self->check_required_attributes(@_);
fb1e11d5 60
1c9db35c 61 $self->apply_attributes(@_);
62 $self->apply_methods(@_);
fb1e11d5 63
1c9db35c 64 $self->apply_override_method_modifiers(@_);
fb1e11d5 65
1c9db35c 66 $self->apply_before_method_modifiers(@_);
67 $self->apply_around_method_modifiers(@_);
68 $self->apply_after_method_modifiers(@_);
fb1e11d5 69}
70
71sub check_role_exclusions { die "Abstract Method" }
72sub check_required_methods { die "Abstract Method" }
709c321c 73sub check_required_attributes { die "Abstract Method" }
74
fb1e11d5 75sub apply_attributes { die "Abstract Method" }
76sub apply_methods { die "Abstract Method" }
77sub apply_override_method_modifiers { die "Abstract Method" }
78sub apply_method_modifiers { die "Abstract Method" }
bca01282 79
80sub apply_before_method_modifiers { (shift)->apply_method_modifiers('before' => @_) }
81sub apply_around_method_modifiers { (shift)->apply_method_modifiers('around' => @_) }
82sub apply_after_method_modifiers { (shift)->apply_method_modifiers('after' => @_) }
fb1e11d5 83
841;
85
86__END__
87
88=pod
89
90=head1 NAME
91
ab76842e 92Moose::Meta::Role::Application - A base class for role application
fb1e11d5 93
94=head1 DESCRIPTION
95
96This is the abstract base class for role applications.
97
98=head2 METHODS
99
100=over 4
101
102=item B<new>
103
104=item B<meta>
105
c4538447 106=item B<get_method_exclusions>
107
108=item B<is_method_excluded>
109
3e19778d 110=item B<get_method_aliases>
111
112=item B<is_aliased_method>
113
114=item B<is_method_aliased>
115
fb1e11d5 116=item B<apply>
117
709c321c 118=item B<check_role_exclusions>
119
fb1e11d5 120=item B<check_required_methods>
121
709c321c 122=item B<check_required_attributes>
fb1e11d5 123
124=item B<apply_attributes>
125
126=item B<apply_methods>
127
128=item B<apply_method_modifiers>
129
130=item B<apply_before_method_modifiers>
131
132=item B<apply_after_method_modifiers>
133
134=item B<apply_around_method_modifiers>
135
136=item B<apply_override_method_modifiers>
137
138=back
139
140=head1 BUGS
141
142All complex software has bugs lurking in it, and this module is no
143exception. If you find a bug please either email me, or add the bug
144to cpan-RT.
145
146=head1 AUTHOR
147
148Stevan Little E<lt>stevan@iinteractive.comE<gt>
149
150=head1 COPYRIGHT AND LICENSE
151
778db3ac 152Copyright 2006-2008 by Infinity Interactive, Inc.
fb1e11d5 153
154L<http://www.iinteractive.com>
155
156This library is free software; you can redistribute it and/or modify
157it under the same terms as Perl itself.
158
159=cut
160