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 $meta = Mouse::Meta::Class->initialize($class);
12 my $self = $meta->new_object($args);
15 if( $self->can('BUILD') ) {
16 for my $class (reverse $meta->linearized_isa) {
17 my $build = Mouse::Util::get_code_ref($class, 'BUILD')
31 (ref($_[0]) eq 'HASH')
32 || $class->meta->throw_error("Single parameters to new() must be a HASH ref");
44 return unless $self->can('DEMOLISH'); # short circuit
54 # We cannot count on being able to retrieve a previously made
55 # metaclass, _or_ being able to make a new one during global
56 # destruction. However, we should still be able to use mro at
57 # that time (at least tests suggest so ;)
59 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
60 my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
70 die $e if $e; # rethrow
77 return unless $self->can('BUILD');
79 for my $class (reverse $self->meta->linearized_isa) {
80 my $build = Mouse::Util::get_code_ref($class, 'BUILD')
92 return unless $self->can('DEMOLISH');
94 # We cannot count on being able to retrieve a previously made
95 # metaclass, _or_ being able to make a new one during global
96 # destruction. However, we should still be able to use mro at
97 # that time (at least tests suggest so ;)
99 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
100 my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
114 Mouse::Object - The base object for Mouse classes
118 This document describes Mouse version 0.40_05
122 =head2 C<< new (Arguments) -> Object >>
124 Instantiates a new C<Mouse::Object>. This is obviously intended for subclasses.
126 =head2 C<< BUILDARGS (Arguments) -> HashRef >>
128 Lets you override the arguments that C<new> takes. Return a hashref of
131 =head2 C<< BUILDALL (\%args) >>
133 Calls C<BUILD> on each class in the class hierarchy. This is called at the
136 =head2 C<< BUILD (\%args) >>
138 You may put any business logic initialization in BUILD methods. You don't
139 need to redispatch or return any specific value.
141 =head2 C<< DEMOLISHALL >>
143 Calls C<DEMOLISH> on each class in the class hierarchy. This is called at
146 =head2 C<< DEMOLISH >>
148 You may put any business logic deinitialization in DEMOLISH methods. You don't
149 need to redispatch or return any specific value.
152 =head2 C<< does ($role_name) -> Bool >>
154 This will check if the invocant's class B<does> a given C<$role_name>.
155 This is similar to "isa" for object, but it checks the roles instead.
157 =head2 C<<dump ($maxdepth) -> Str >>
161 C'mon, how many times have you written the following code while debugging:
166 It can get seriously annoying, so why not just use this.
168 The implementation was lifted directly from Moose::Object.