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 if (ref($attribute->{default}) eq 'CODE') {
23 $instance->{$key} = $attribute->{default}->();
24 Scalar::Util::weaken($instance->{$key})
25 if $attribute->{weak_ref};
28 $instance->{$key} = $attribute->{default};
29 Scalar::Util::weaken($instance->{$key})
30 if $attribute->{weak_ref};
35 if ($attribute->{required}) {
36 confess "Attribute '$attribute->{name}' is required";
41 if (exists($args{$key})) {
42 $instance->{$key} = $args{$key};
43 Scalar::Util::weaken($instance->{$key})
44 if $attribute->{weak_ref};
46 if ($attribute->{trigger}) {
47 $attribute->{trigger}->($instance, $args{$key}, $attribute);
52 $instance->BUILDALL(\%args);
57 sub DESTROY { shift->DEMOLISHALL }
63 return unless $self->can('BUILD');
67 for my $class ($self->meta->linearized_isa) {
68 my $code = *{ $class . '::BUILD' }{CODE}
78 return unless $self->can('DEMOLISH');
82 for my $class ($self->meta->linearized_isa) {
83 my $code = *{ $class . '::DEMOLISH' }{CODE}
95 Mouse::Object - we don't need to steenkin' constructor
99 =head2 new arguments -> object
101 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
103 =head2 BUILDALL \%args
105 Calls L</BUILD> on each class in the class hierarchy. This is called at the
110 You may put any business logic initialization in BUILD methods. You don't
111 need to redispatch or return any specific value.
115 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
120 You may put any business logic deinitialization in DEMOLISH methods. You don't
121 need to redispatch or return any specific value.