7 use Scalar::Util qw/blessed weaken/;
13 my $args = $class->BUILDARGS(@_);
15 my $instance = bless {}, $class;
17 for my $attribute ($class->meta->compute_all_applicable_attributes) {
18 my $from = $attribute->init_arg;
19 my $key = $attribute->name;
22 if (defined($from) && exists($args->{$from})) {
23 $attribute->verify_type_constraint($args->{$from})
24 if $attribute->has_type_constraint;
26 $instance->{$key} = $args->{$from};
28 weaken($instance->{$key})
29 if ref($instance->{$key}) && $attribute->is_weak_ref;
31 if ($attribute->has_trigger) {
32 $attribute->trigger->($instance, $args->{$from}, $attribute);
36 if ($attribute->has_default || $attribute->has_builder) {
37 unless ($attribute->is_lazy) {
38 my $default = $attribute->default;
39 my $builder = $attribute->builder;
40 my $value = $attribute->has_builder
42 : ref($default) eq 'CODE'
46 $attribute->verify_type_constraint($value)
47 if $attribute->has_type_constraint;
49 $instance->{$key} = $value;
51 weaken($instance->{$key})
52 if ref($instance->{$key}) && $attribute->is_weak_ref;
56 if ($attribute->is_required) {
57 confess "Attribute (".$attribute->name.") is required";
63 $instance->BUILDALL($args);
73 (ref($_[0]) eq 'HASH')
74 || confess "Single parameters to new() must be a HASH ref";
85 sub DESTROY { shift->DEMOLISHALL }
91 return unless $self->can('BUILD');
95 for my $class (reverse $self->meta->linearized_isa) {
96 my $code = *{ $class . '::BUILD' }{CODE}
106 return unless $self->can('DEMOLISH');
110 for my $class ($self->meta->linearized_isa) {
111 my $code = *{ $class . '::DEMOLISH' }{CODE}
123 Mouse::Object - we don't need to steenkin' constructor
127 =head2 new arguments -> object
129 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
131 =head2 BUILDALL \%args
133 Calls L</BUILD> on each class in the class hierarchy. This is called at the
138 You may put any business logic initialization in BUILD methods. You don't
139 need to redispatch or return any specific value.
143 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
148 You may put any business logic deinitialization in DEMOLISH methods. You don't
149 need to redispatch or return any specific value.