6 use Mouse::Util qw/weaken/;
12 my $args = $class->BUILDARGS(@_);
14 my $instance = bless {}, $class;
16 for my $attribute ($class->meta->compute_all_applicable_attributes) {
17 my $from = $attribute->init_arg;
18 my $key = $attribute->name;
21 if (defined($from) && exists($args->{$from})) {
22 $args->{$from} = $attribute->coerce_constraint($args->{$from})
23 if $attribute->is_coerce;
24 $attribute->verify_type_constraint($args->{$from})
25 if $attribute->has_type_constraint;
27 $instance->{$key} = $args->{$from};
29 weaken($instance->{$key})
30 if ref($instance->{$key}) && $attribute->is_weak_ref;
32 if ($attribute->has_trigger) {
33 $attribute->trigger->($instance, $args->{$from}, $attribute);
37 if ($attribute->has_default || $attribute->has_builder) {
38 unless ($attribute->is_lazy) {
39 my $default = $attribute->default;
40 my $builder = $attribute->builder;
41 my $value = $attribute->has_builder
43 : ref($default) eq 'CODE'
47 $value = $attribute->coerce_constraint($value)
48 if $attribute->is_coerce;
49 $attribute->verify_type_constraint($value)
50 if $attribute->has_type_constraint;
52 $instance->{$key} = $value;
54 weaken($instance->{$key})
55 if ref($instance->{$key}) && $attribute->is_weak_ref;
59 if ($attribute->is_required) {
60 confess "Attribute (".$attribute->name.") is required";
66 $instance->BUILDALL($args);
76 (ref($_[0]) eq 'HASH')
77 || confess "Single parameters to new() must be a HASH ref";
88 sub DESTROY { shift->DEMOLISHALL }
94 return unless $self->can('BUILD');
96 for my $class (reverse $self->meta->linearized_isa) {
99 my $code = *{ $class . '::BUILD' }{CODE}
109 return unless $self->can('DEMOLISH');
113 for my $class ($self->meta->linearized_isa) {
114 my $code = *{ $class . '::DEMOLISH' }{CODE}
126 Mouse::Object - we don't need to steenkin' constructor
130 =head2 new arguments -> object
132 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
134 =head2 BUILDALL \%args
136 Calls L</BUILD> on each class in the class hierarchy. This is called at the
141 You may put any business logic initialization in BUILD methods. You don't
142 need to redispatch or return any specific value.
146 Lets you override the arguments that C<new> takes. Return a hashref of
151 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
156 You may put any business logic deinitialization in DEMOLISH methods. You don't
157 need to redispatch or return any specific value.