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 new arguments -> object
81 Instantiates a new Mouse::Object. This is obviously intended for subclasses.
83 =head2 BUILDALL \%args
85 Calls L</BUILD> on each class in the class hierarchy. This is called at the
90 You may put any business logic initialization in BUILD methods. You don't
91 need to redispatch or return any specific value.
95 Lets you override the arguments that C<new> takes. Return a hashref of
100 Calls L</DEMOLISH> on each class in the class hierarchy. This is called at
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 does $role_name
111 This will check if the invocant's class "does" a given C<$role_name>.
112 This is similar to "isa" for object, but it checks the roles instead.
115 =head2 B<dump ($maxdepth)>
119 C'mon, how many times have you written the following code while debugging:
124 It can get seriously annoying, so why not just use this.
126 The implementation was lifted directly from Moose::Object.