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