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