2 package Moose::Meta::Method::Constructor;
8 use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
11 our $VERSION = '1.9900';
12 our $AUTHORITY = 'cpan:STEVAN';
14 use base 'Moose::Meta::Method',
15 'Class::MOP::Method::Constructor';
21 my $meta = $options{metaclass};
23 (ref $options{options} eq 'HASH')
24 || $class->throw_error("You must pass a hash of options", data => $options{options});
26 ($options{package_name} && $options{name})
27 || $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT");
31 'package_name' => $options{package_name},
32 'name' => $options{name},
33 'options' => $options{options},
34 'associated_metaclass' => $meta,
35 '_expected_method_class' => $options{_expected_method_class} || 'Moose::Object',
38 # we don't want this creating
39 # a cycle in the code, if not
41 weaken($self->{'associated_metaclass'});
43 $self->_initialize_body;
50 sub _initialize_body {
52 $self->{'body'} = $self->_generate_constructor_method_inline;
55 sub _eval_environment {
58 my $attrs = $self->_attributes;
60 my $defaults = [map { $_->default } @$attrs];
62 # We need to check if the attribute ->can('type_constraint')
63 # since we may be trying to immutabilize a Moose meta class,
64 # which in turn has attributes which are Class::MOP::Attribute
65 # objects, rather than Moose::Meta::Attribute. And
66 # Class::MOP::Attribute attributes have no type constraints.
67 # However we need to make sure we leave an undef value there
68 # because the inlined code is using the index of the attributes
69 # to determine where to find the type constraint
71 my @type_constraints = map {
72 $_->can('type_constraint') ? $_->type_constraint : undef
75 my @type_constraint_bodies = map {
76 defined $_ ? $_->_compiled_type_constraint : undef;
82 '$defaults' => \$defaults,
83 '@type_constraints' => \@type_constraints,
84 '@type_constraint_bodies' => \@type_constraint_bodies,
96 Moose::Meta::Method::Constructor - Method Meta Object for constructors
100 This class is a subclass of L<Class::MOP::Method::Constructor> that
101 provides additional Moose-specific functionality
103 To understand this class, you should read the the
104 L<Class::MOP::Method::Constructor> documentation as well.
108 C<Moose::Meta::Method::Constructor> is a subclass of
109 L<Moose::Meta::Method> I<and> L<Class::MOP::Method::Constructor>.
113 See L<Moose/BUGS> for details on reporting bugs.
117 Stevan Little E<lt>stevan@iinteractive.comE<gt>
119 =head1 COPYRIGHT AND LICENSE
121 Copyright 2006-2010 by Infinity Interactive, Inc.
123 L<http://www.iinteractive.com>
125 This library is free software; you can redistribute it and/or modify
126 it under the same terms as Perl itself.