bump version to 1.19
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application.pm
1 package Moose::Meta::Role::Application;
2
3 use strict;
4 use warnings;
5 use metaclass;
6
7 our $VERSION   = '1.19';
8 $VERSION = eval $VERSION;
9 our $AUTHORITY = 'cpan:STEVAN';
10
11 __PACKAGE__->meta->add_attribute('method_exclusions' => (
12     init_arg => '-excludes',
13     reader   => 'get_method_exclusions',
14     default  => sub { [] }
15 ));
16
17 __PACKAGE__->meta->add_attribute('method_aliases' => (
18     init_arg => '-alias',
19     reader   => 'get_method_aliases',
20     default  => sub { {} }
21 ));
22
23 sub new {
24     my ($class, %params) = @_;
25     $class->_new(\%params);
26 }
27
28 sub is_method_excluded {
29     my ($self, $method_name) = @_;
30     foreach (@{$self->get_method_exclusions}) {
31         return 1 if $_ eq $method_name;
32     }
33     return 0;
34 }
35
36 sub is_method_aliased {
37     my ($self, $method_name) = @_;
38     exists $self->get_method_aliases->{$method_name} ? 1 : 0
39 }
40
41 sub is_aliased_method {
42     my ($self, $method_name) = @_;
43     my %aliased_names = reverse %{$self->get_method_aliases};
44     exists $aliased_names{$method_name} ? 1 : 0;
45 }
46
47 sub apply {
48     my $self = shift;
49
50     $self->check_role_exclusions(@_);
51     $self->check_required_methods(@_);
52     $self->check_required_attributes(@_);
53
54     $self->apply_attributes(@_);
55     $self->apply_methods(@_);
56
57     $self->apply_override_method_modifiers(@_);
58
59     $self->apply_before_method_modifiers(@_);
60     $self->apply_around_method_modifiers(@_);
61     $self->apply_after_method_modifiers(@_);
62 }
63
64 sub check_role_exclusions           { Carp::croak "Abstract Method" }
65 sub check_required_methods          { Carp::croak "Abstract Method" }
66 sub check_required_attributes       { Carp::croak "Abstract Method" }
67
68 sub apply_attributes                { Carp::croak "Abstract Method" }
69 sub apply_methods                   { Carp::croak "Abstract Method" }
70 sub apply_override_method_modifiers { Carp::croak "Abstract Method" }
71 sub apply_method_modifiers          { Carp::croak "Abstract Method" }
72
73 sub apply_before_method_modifiers   { (shift)->apply_method_modifiers('before' => @_) }
74 sub apply_around_method_modifiers   { (shift)->apply_method_modifiers('around' => @_) }
75 sub apply_after_method_modifiers    { (shift)->apply_method_modifiers('after'  => @_) }
76
77 1;
78
79 __END__
80
81 =pod
82
83 =head1 NAME
84
85 Moose::Meta::Role::Application - A base class for role application
86
87 =head1 DESCRIPTION
88
89 This is the abstract base class for role applications.
90
91 The API for this class and its subclasses still needs some
92 consideration, and is intentionally not yet documented.
93
94 =head2 METHODS
95
96 =over 4
97
98 =item B<new>
99
100 =item B<meta>
101
102 =item B<get_method_exclusions>
103
104 =item B<is_method_excluded>
105
106 =item B<get_method_aliases>
107
108 =item B<is_aliased_method>
109
110 =item B<is_method_aliased>
111
112 =item B<apply>
113
114 =item B<check_role_exclusions>
115
116 =item B<check_required_methods>
117
118 =item B<check_required_attributes>
119
120 =item B<apply_attributes>
121
122 =item B<apply_methods>
123
124 =item B<apply_method_modifiers>
125
126 =item B<apply_before_method_modifiers>
127
128 =item B<apply_after_method_modifiers>
129
130 =item B<apply_around_method_modifiers>
131
132 =item B<apply_override_method_modifiers>
133
134 =back
135
136 =head1 BUGS
137
138 See L<Moose/BUGS> for details on reporting bugs.
139
140 =head1 AUTHOR
141
142 Stevan Little E<lt>stevan@iinteractive.comE<gt>
143
144 =head1 COPYRIGHT AND LICENSE
145
146 Copyright 2006-2010 by Infinity Interactive, Inc.
147
148 L<http://www.iinteractive.com>
149
150 This library is free software; you can redistribute it and/or modify
151 it under the same terms as Perl itself.
152
153 =cut
154