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