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')
30 return unless $self->can('DEMOLISH'); # short circuit
40 # We cannot count on being able to retrieve a previously made
41 # metaclass, _or_ being able to make a new one during global
42 # destruction. However, we should still be able to use mro at
43 # that time (at least tests suggest so ;)
45 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
46 my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
56 die $e if $e; # rethrow
63 return unless $self->can('BUILD');
65 for my $class (reverse $self->meta->linearized_isa) {
66 my $build = Mouse::Util::get_code_ref($class, 'BUILD')
78 return unless $self->can('DEMOLISH');
80 # We cannot count on being able to retrieve a previously made
81 # metaclass, _or_ being able to make a new one during global
82 # destruction. However, we should still be able to use mro at
83 # that time (at least tests suggest so ;)
85 foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
86 my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
100 Mouse::Object - The base object for Mouse classes
104 This document describes Mouse version 0.40_05
108 =head2 C<< new (Arguments) -> Object >>
110 Instantiates a new C<Mouse::Object>. This is obviously intended for subclasses.
112 =head2 C<< BUILDARGS (Arguments) -> HashRef >>
114 Lets you override the arguments that C<new> takes. Return a hashref of
117 =head2 C<< BUILDALL (\%args) >>
119 Calls C<BUILD> on each class in the class hierarchy. This is called at the
122 =head2 C<< BUILD (\%args) >>
124 You may put any business logic initialization in BUILD methods. You don't
125 need to redispatch or return any specific value.
127 =head2 C<< DEMOLISHALL >>
129 Calls C<DEMOLISH> on each class in the class hierarchy. This is called at
132 =head2 C<< DEMOLISH >>
134 You may put any business logic deinitialization in DEMOLISH methods. You don't
135 need to redispatch or return any specific value.
138 =head2 C<< does ($role_name) -> Bool >>
140 This will check if the invocant's class B<does> a given C<$role_name>.
141 This is similar to "isa" for object, but it checks the roles instead.
143 =head2 C<<dump ($maxdepth) -> Str >>
147 C'mon, how many times have you written the following code while debugging:
152 It can get seriously annoying, so why not just use this.
154 The implementation was lifted directly from Moose::Object.