7 use Scalar::Util qw/blessed weaken/;
13 my $instance = bless {}, $class;
15 for my $attribute ($class->meta->attributes) {
16 my $key = $attribute->init_arg;
19 if (!exists($args{$key})) {
20 if ($attribute->has_default || $attribute->has_builder) {
21 unless ($attribute->is_lazy) {
22 my $default = $attribute->default;
23 my $builder = $attribute->builder;
24 my $value = $attribute->has_builder
26 : ref($default) eq 'CODE'
30 $attribute->verify_type_constraint($value)
31 if $attribute->has_type_constraint;
33 $instance->{$key} = $value;
35 weaken($instance->{$key})
36 if $attribute->weak_ref;
40 if ($attribute->is_required) {
41 confess "Attribute (".$attribute->name.") is required";
46 if (exists($args{$key})) {
47 $attribute->verify_type_constraint($args{$key})
48 if $attribute->has_type_constraint;
50 $instance->{$key} = $args{$key};
52 weaken($instance->{$key})
53 if $attribute->weak_ref;
55 if ($attribute->has_trigger) {
56 $attribute->trigger->($instance, $args{$key}, $attribute);
61 $instance->BUILDALL(\%args);
66 sub DESTROY { shift->DEMOLISHALL }
72 return unless $self->can('BUILD');
76 for my $class ($self->meta->linearized_isa) {
77 my $code = *{ $class . '::BUILD' }{CODE}
87 return unless $self->can('DEMOLISH');
91 for my $class ($self->meta->linearized_isa) {
92 my $code = *{ $class . '::DEMOLISH' }{CODE}
104 Mouse::Object - we don't need to steenkin' constructor
108 =head2 new arguments -> object
110 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
112 =head2 BUILDALL \%args
114 Calls L</BUILD> on each class in the class hierarchy. This is called at the
119 You may put any business logic initialization in BUILD methods. You don't
120 need to redispatch or return any specific value.
124 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
129 You may put any business logic deinitialization in DEMOLISH methods. You don't
130 need to redispatch or return any specific value.