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 $attribute->verify_type_constraint($args->{$from})
23 if $attribute->has_type_constraint;
25 $instance->{$key} = $args->{$from};
27 weaken($instance->{$key})
28 if ref($instance->{$key}) && $attribute->is_weak_ref;
30 if ($attribute->has_trigger) {
31 $attribute->trigger->($instance, $args->{$from}, $attribute);
35 if ($attribute->has_default || $attribute->has_builder) {
36 unless ($attribute->is_lazy) {
37 my $default = $attribute->default;
38 my $builder = $attribute->builder;
39 my $value = $attribute->has_builder
41 : ref($default) eq 'CODE'
45 $attribute->verify_type_constraint($value)
46 if $attribute->has_type_constraint;
48 $instance->{$key} = $value;
50 weaken($instance->{$key})
51 if ref($instance->{$key}) && $attribute->is_weak_ref;
55 if ($attribute->is_required) {
56 confess "Attribute (".$attribute->name.") is required";
62 $instance->BUILDALL($args);
72 (ref($_[0]) eq 'HASH')
73 || confess "Single parameters to new() must be a HASH ref";
84 sub DESTROY { shift->DEMOLISHALL }
90 return unless $self->can('BUILD');
92 for my $class (reverse $self->meta->linearized_isa) {
95 my $code = *{ $class . '::BUILD' }{CODE}
105 return unless $self->can('DEMOLISH');
109 for my $class ($self->meta->linearized_isa) {
110 my $code = *{ $class . '::DEMOLISH' }{CODE}
122 Mouse::Object - we don't need to steenkin' constructor
126 =head2 new arguments -> object
128 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
130 =head2 BUILDALL \%args
132 Calls L</BUILD> on each class in the class hierarchy. This is called at the
137 You may put any business logic initialization in BUILD methods. You don't
138 need to redispatch or return any specific value.
142 Lets you override the arguments that C<new> takes. Return a hashref of
147 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
152 You may put any business logic deinitialization in DEMOLISH methods. You don't
153 need to redispatch or return any specific value.