2 use Mouse::Util qw(does dump); # enables strict and warnings
7 $class->meta->throw_error('Cannot call new() on an instance') if ref $class;
9 my $args = $class->BUILDARGS(@_);
11 my $instance = Mouse::Meta::Class->initialize($class)->new_object($args);
12 $instance->BUILDALL($args);
20 (ref($_[0]) eq 'HASH')
21 || $class->meta->throw_error("Single parameters to new() must be a HASH ref");
44 die $e if $e; # rethrow
51 return unless $self->can('BUILD');
53 for my $class (reverse $self->meta->linearized_isa) {
54 my $build = Mouse::Util::get_code_ref($class, 'BUILD')
66 return unless $self->can('DEMOLISH');
68 # We cannot count on being able to retrieve a previously made
69 # metaclass, _or_ being able to make a new one during global
70 # destruction. However, we should still be able to use mro at
71 # that time (at least tests suggest so ;)
73 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
74 my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
88 Mouse::Object - The base object for Mouse classes
92 This document describes Mouse version 0.40_01
96 =head2 C<< new (Arguments) -> Object >>
98 Instantiates a new C<Mouse::Object>. This is obviously intended for subclasses.
100 =head2 C<< BUILDARGS (Arguments) -> HashRef >>
102 Lets you override the arguments that C<new> takes. Return a hashref of
105 =head2 C<< BUILDALL (\%args) >>
107 Calls C<BUILD> on each class in the class hierarchy. This is called at the
110 =head2 C<< BUILD (\%args) >>
112 You may put any business logic initialization in BUILD methods. You don't
113 need to redispatch or return any specific value.
115 =head2 C<< DEMOLISHALL >>
117 Calls C<DEMOLISH> on each class in the class hierarchy. This is called at
120 =head2 C<< DEMOLISH >>
122 You may put any business logic deinitialization in DEMOLISH methods. You don't
123 need to redispatch or return any specific value.
126 =head2 C<< does ($role_name) -> Bool >>
128 This will check if the invocant's class B<does> a given C<$role_name>.
129 This is similar to "isa" for object, but it checks the roles instead.
131 =head2 C<<dump ($maxdepth) -> Str >>
135 C'mon, how many times have you written the following code while debugging:
140 It can get seriously annoying, so why not just use this.
142 The implementation was lifted directly from Moose::Object.