use hash refs with _new
[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 = $class->_new(\%options);
22     
23     $self->initialize_body;
24     
25     return $self;
26 }
27
28 sub _new {
29     my $class = shift;
30     my $options = @_ == 1 ? $_[0] : {@_};
31
32     $options->{is_inline} ||= 0;
33     $options->{body} ||= undef;
34
35     bless $options, $class;
36 }
37
38 ## accessors
39
40 sub is_inline { (shift)->{'is_inline'} }
41
42 sub initialize_body {
43     confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
44 }
45
46
47
48 1;
49
50 __END__
51
52 =pod
53
54 =head1 NAME 
55
56 Class::MOP::Method::Generated - Abstract base class for generated methods
57
58 =head1 DESCRIPTION
59
60 This is a C<Class::MOP::Method> subclass which is used interally 
61 by 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
69 This creates the method based on the criteria in C<%options>, 
70 these options are:
71
72 =over 4
73
74 =item I<is_inline>
75
76 This is a boolean to indicate if the method should be generated
77 as a closure, or as a more optimized inline version.
78
79 =back
80
81 =item B<is_inline>
82
83 This returns the boolean which was passed into C<new>.
84
85 =item B<initialize_body>
86
87 This is an abstract method and will throw an exception if called.
88
89 =back
90
91 =head1 AUTHORS
92
93 Stevan Little E<lt>stevan@iinteractive.comE<gt>
94
95 =head1 COPYRIGHT AND LICENSE
96
97 Copyright 2006-2008 by Infinity Interactive, Inc.
98
99 L<http://www.iinteractive.com>
100
101 This library is free software; you can redistribute it and/or modify
102 it under the same terms as Perl itself. 
103
104 =cut
105