5 use Mouse::Util qw(does dump);
10 $class->throw_error('Cannot call new() on an instance') if ref $class;
12 my $args = $class->BUILDARGS(@_);
14 my $instance = Mouse::Meta::Class->initialize($class)->new_object($args);
15 $instance->BUILDALL($args);
23 (ref($_[0]) eq 'HASH')
24 || $class->meta->throw_error("Single parameters to new() must be a HASH ref");
32 sub DESTROY { shift->DEMOLISHALL }
38 return unless $self->can('BUILD');
40 for my $class (reverse $self->meta->linearized_isa) {
43 my $code = *{ $class . '::BUILD' }{CODE}
54 return unless $self->can('DEMOLISH');
56 # We cannot count on being able to retrieve a previously made
57 # metaclass, _or_ being able to make a new one during global
58 # destruction. However, we should still be able to use mro at
59 # that time (at least tests suggest so ;)
61 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
62 my $demolish = do{ no strict 'refs'; *{"${class}::DEMOLISH"}{CODE} };
75 Mouse::Object - we don't need to steenkin' constructor
79 =head2 C<< new arguments -> Object >>
81 Instantiates a new C<Mouse::Object>. This is obviously intended for subclasses.
83 =head2 C<< BUILDARGS(@args) -> HashRef >>
85 Lets you override the arguments that C<new> takes. Return a hashref of
88 =head2 C<< BUILDALL \%args >>
90 Calls C<BUILD> on each class in the class hierarchy. This is called at the
93 =head2 C<< BUILD \%args >>
95 You may put any business logic initialization in BUILD methods. You don't
96 need to redispatch or return any specific value.
98 =head2 C<< DEMOLISHALL >>
100 Calls C<DEMOLISH> on each class in the class hierarchy. This is called at
103 =head2 C<< DEMOLISH >>
105 You may put any business logic deinitialization in DEMOLISH methods. You don't
106 need to redispatch or return any specific value.
109 =head2 C<< does ($role_name) -> Bool >>
111 This will check if the invocant's class B<does> a given C<$role_name>.
112 This is similar to "isa" for object, but it checks the roles instead.
114 =head2 C<<dump ($maxdepth) -> Str >>
118 C'mon, how many times have you written the following code while debugging:
123 It can get seriously annoying, so why not just use this.
125 The implementation was lifted directly from Moose::Object.