adding method exclusion
[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   = '0.01';
8 our $AUTHORITY = 'cpan:STEVAN';
9
10 __PACKAGE__->meta->add_attribute('method_exclusions' => (
11     init_arg => 'excludes',
12     reader   => 'get_method_exclusions',
13     default  => sub { [] }
14 ));
15
16 sub new { 
17     my ($class, %params) = @_;
18     
19     if (exists $params{excludes}) {
20         # I wish we had coercion here :)
21         $params{excludes} = (ref $params{excludes} eq 'ARRAY' 
22                                 ? $params{excludes} 
23                                 : [ $params{excludes} ]);
24     }
25     
26     $class->meta->new_object(%params);
27 }
28
29 sub is_method_excluded {
30     my ($self, $method_name) = @_;
31     foreach (@{$self->get_method_exclusions}) {
32         return 1 if $_ eq $method_name;
33     }
34     return 0;
35 }
36
37 sub apply {
38     my $self = shift;
39
40     $self->check_role_exclusions(@_);
41     $self->check_required_methods(@_);
42     $self->check_required_attributes(@_);
43     
44     $self->apply_attributes(@_);
45     $self->apply_methods(@_);    
46     
47     $self->apply_override_method_modifiers(@_);
48     
49     $self->apply_before_method_modifiers(@_);
50     $self->apply_around_method_modifiers(@_);
51     $self->apply_after_method_modifiers(@_);
52 }
53
54 sub check_role_exclusions           { die "Abstract Method" }
55 sub check_required_methods          { die "Abstract Method" }
56 sub check_required_attributes       { die "Abstract Method" }
57
58 sub apply_attributes                { die "Abstract Method" }
59 sub apply_methods                   { die "Abstract Method" }
60 sub apply_override_method_modifiers { die "Abstract Method" }
61 sub apply_method_modifiers          { die "Abstract Method" }
62
63 sub apply_before_method_modifiers   { (shift)->apply_method_modifiers('before' => @_) }
64 sub apply_around_method_modifiers   { (shift)->apply_method_modifiers('around' => @_) }
65 sub apply_after_method_modifiers    { (shift)->apply_method_modifiers('after'  => @_) }
66
67 1;
68
69 __END__
70
71 =pod
72
73 =head1 NAME
74
75 Moose::Meta::Role::Application
76
77 =head1 DESCRIPTION
78
79 This is the abstract base class for role applications.
80
81 =head2 METHODS
82
83 =over 4
84
85 =item B<new>
86
87 =item B<meta>
88
89 =item B<get_method_exclusions>
90
91 =item B<is_method_excluded>
92
93 =item B<apply>
94
95 =item B<check_role_exclusions>
96
97 =item B<check_required_methods>
98
99 =item B<check_required_attributes>
100
101 =item B<apply_attributes>
102
103 =item B<apply_methods>
104
105 =item B<apply_method_modifiers>
106
107 =item B<apply_before_method_modifiers>
108
109 =item B<apply_after_method_modifiers>
110
111 =item B<apply_around_method_modifiers>
112
113 =item B<apply_override_method_modifiers>
114
115 =back
116
117 =head1 BUGS
118
119 All complex software has bugs lurking in it, and this module is no
120 exception. If you find a bug please either email me, or add the bug
121 to cpan-RT.
122
123 =head1 AUTHOR
124
125 Stevan Little E<lt>stevan@iinteractive.comE<gt>
126
127 =head1 COPYRIGHT AND LICENSE
128
129 Copyright 2006-2008 by Infinity Interactive, Inc.
130
131 L<http://www.iinteractive.com>
132
133 This library is free software; you can redistribute it and/or modify
134 it under the same terms as Perl itself.
135
136 =cut
137