7 use Scalar::Util qw/blessed weaken/;
13 my $instance = bless {}, $class;
15 for my $attribute (values %{ $class->meta->get_attribute_map }) {
16 my $from = $attribute->init_arg;
17 my $key = $attribute->name;
20 if (!exists($args{$from})) {
21 if ($attribute->has_default || $attribute->has_builder) {
22 unless ($attribute->is_lazy) {
23 my $default = $attribute->default;
24 my $builder = $attribute->builder;
25 my $value = $attribute->has_builder
27 : ref($default) eq 'CODE'
31 $attribute->verify_type_constraint($value)
32 if $attribute->has_type_constraint;
34 $instance->{$key} = $value;
36 weaken($instance->{$key})
37 if ref($instance->{$key}) && $attribute->is_weak_ref;
41 if ($attribute->is_required) {
42 confess "Attribute (".$attribute->name.") is required";
47 if (exists($args{$from})) {
48 $attribute->verify_type_constraint($args{$from})
49 if $attribute->has_type_constraint;
51 $instance->{$key} = $args{$from};
53 weaken($instance->{$key})
54 if ref($instance->{$key}) && $attribute->is_weak_ref;
56 if ($attribute->has_trigger) {
57 $attribute->trigger->($instance, $args{$from}, $attribute);
62 $instance->BUILDALL(\%args);
67 sub DESTROY { shift->DEMOLISHALL }
73 return unless $self->can('BUILD');
77 for my $class ($self->meta->linearized_isa) {
78 my $code = *{ $class . '::BUILD' }{CODE}
88 return unless $self->can('DEMOLISH');
92 for my $class ($self->meta->linearized_isa) {
93 my $code = *{ $class . '::DEMOLISH' }{CODE}
105 Mouse::Object - we don't need to steenkin' constructor
109 =head2 new arguments -> object
111 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
113 =head2 BUILDALL \%args
115 Calls L</BUILD> on each class in the class hierarchy. This is called at the
120 You may put any business logic initialization in BUILD methods. You don't
121 need to redispatch or return any specific value.
125 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
130 You may put any business logic deinitialization in DEMOLISH methods. You don't
131 need to redispatch or return any specific value.