use hash refs with _new
[gitmo/Class-MOP.git] / lib / Class / MOP / Method / Generated.pm
CommitLineData
565f0cbb 1
2package Class::MOP::Method::Generated;
3
4use strict;
5use warnings;
6
7use Carp 'confess';
8
2e5c1a3f 9our $VERSION = '0.65';
565f0cbb 10our $AUTHORITY = 'cpan:STEVAN';
11
12use base 'Class::MOP::Method';
13
14sub new {
15 my $class = shift;
16 my %options = @_;
17
b38f3848 18 ($options{package_name} && $options{name})
32202ce2 19 || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
b38f3848 20
0bfc85b8 21 my $self = $class->_new(\%options);
565f0cbb 22
23 $self->initialize_body;
24
25 return $self;
26}
27
e3a72dbc 28sub _new {
0bfc85b8 29 my $class = shift;
30 my $options = @_ == 1 ? $_[0] : {@_};
e3a72dbc 31
0bfc85b8 32 $options->{is_inline} ||= 0;
33 $options->{body} ||= undef;
e3a72dbc 34
0bfc85b8 35 bless $options, $class;
e3a72dbc 36}
37
565f0cbb 38## accessors
39
8683db0e 40sub is_inline { (shift)->{'is_inline'} }
565f0cbb 41
42sub initialize_body {
43 confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
44}
45
46
47
481;
49
50__END__
51
52=pod
53
54=head1 NAME
55
56Class::MOP::Method::Generated - Abstract base class for generated methods
57
58=head1 DESCRIPTION
59
60This is a C<Class::MOP::Method> subclass which is used interally
61by C<Class::MOP::Method::Accessor> and C<Class::MOP::Method::Constructor>.
62
63=head1 METHODS
64
65=over 4
66
67=item B<new (%options)>
68
69This creates the method based on the criteria in C<%options>,
70these options are:
71
72=over 4
73
74=item I<is_inline>
75
76This is a boolean to indicate if the method should be generated
77as a closure, or as a more optimized inline version.
78
79=back
80
81=item B<is_inline>
82
83This returns the boolean which was passed into C<new>.
84
85=item B<initialize_body>
86
87This is an abstract method and will throw an exception if called.
88
89=back
90
91=head1 AUTHORS
92
93Stevan Little E<lt>stevan@iinteractive.comE<gt>
94
95=head1 COPYRIGHT AND LICENSE
96
69e3ab0a 97Copyright 2006-2008 by Infinity Interactive, Inc.
565f0cbb 98
99L<http://www.iinteractive.com>
100
101This library is free software; you can redistribute it and/or modify
102it under the same terms as Perl itself.
103
104=cut
105