7 use Scalar::Util 'blessed';
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 (exists($attribute->{default})) {
21 unless ($attribute->{lazy}) {
22 my $default = ref($attribute->{default}) eq 'CODE'
23 ? $attribute->{default}->()
24 : $attribute->{default};
26 $attribute->verify_type_constraint($default)
27 if $attribute->has_type_constraint;
29 $instance->{$key} = $default;
31 Scalar::Util::weaken($instance->{$key})
32 if $attribute->{weak_ref};
36 if ($attribute->{required}) {
37 confess "Attribute '$attribute->{name}' is required";
42 if (exists($args{$key})) {
43 $attribute->verify_type_constraint($args{$key})
44 if $attribute->has_type_constraint;
46 $instance->{$key} = $args{$key};
48 Scalar::Util::weaken($instance->{$key})
49 if $attribute->{weak_ref};
51 if ($attribute->{trigger}) {
52 $attribute->{trigger}->($instance, $args{$key}, $attribute);
57 $instance->BUILDALL(\%args);
62 sub DESTROY { shift->DEMOLISHALL }
68 return unless $self->can('BUILD');
72 for my $class ($self->meta->linearized_isa) {
73 my $code = *{ $class . '::BUILD' }{CODE}
83 return unless $self->can('DEMOLISH');
87 for my $class ($self->meta->linearized_isa) {
88 my $code = *{ $class . '::DEMOLISH' }{CODE}
100 Mouse::Object - we don't need to steenkin' constructor
104 =head2 new arguments -> object
106 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
108 =head2 BUILDALL \%args
110 Calls L</BUILD> on each class in the class hierarchy. This is called at the
115 You may put any business logic initialization in BUILD methods. You don't
116 need to redispatch or return any specific value.
120 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
125 You may put any business logic deinitialization in DEMOLISH methods. You don't
126 need to redispatch or return any specific value.