9 use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class';
10 use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class';
12 our $VERSION = '0.73';
13 $VERSION = eval $VERSION;
14 our $AUTHORITY = 'cpan:STEVAN';
19 my $params = $class->BUILDARGS(@_);
21 # We want to support passing $self->new, but initialize
22 # takes only an unblessed class name
23 my $real_class = Scalar::Util::blessed($class) || $class;
24 my $self = Class::MOP::Class->initialize($real_class)->new_object($params);
26 $self->BUILDALL($params);
33 if ( scalar @_ == 1 ) {
34 unless ( defined $_[0] && ref $_[0] eq 'HASH' ) {
35 Class::MOP::class_of($class)->throw_error(
36 "Single parameters to new() must be a HASH ref",
39 return { %{ $_[0] } };
47 # NOTE: we ask Perl if we even
48 # need to do this first, to avoid
49 # extra meta level calls
50 return unless $_[0]->can('BUILD');
51 my ($self, $params) = @_;
52 foreach my $method (reverse Class::MOP::class_of($self)->find_all_methods_by_name('BUILD')) {
53 $method->{code}->execute($self, $params);
59 # NOTE: we ask Perl if we even
60 # need to do this first, to avoid
61 # extra meta level calls
62 return unless $self->can('DEMOLISH');
63 foreach my $method (Class::MOP::class_of($self)->find_all_methods_by_name('DEMOLISH')) {
64 $method->{code}->execute($self);
69 # if we have an exception here ...
73 # run DEMOLISHALL ourselves, ...
78 # otherwise it is normal destruction
82 # support for UNIVERSAL::DOES ...
84 my $does = UNIVERSAL->can("DOES") ? "SUPER::DOES" : "isa";
86 my ( $self, $class_or_role_name ) = @_;
87 return $self->'.$does.'($class_or_role_name)
88 || $self->does($class_or_role_name);
92 # new does() methods will be created
93 # as appropiate see Moose::Meta::Role
95 my ($self, $role_name) = @_;
96 my $meta = Class::MOP::class_of($self);
98 || $meta->throw_error("You much supply a role name to does()");
99 foreach my $class ($meta->class_precedence_list) {
100 my $m = $meta->initialize($class);
102 if $m->can('does_role') && $m->does_role($role_name);
109 require Data::Dumper;
110 local $Data::Dumper::Maxdepth = shift if @_;
111 Data::Dumper::Dumper $self;
122 Moose::Object - The base object for Moose
126 This class is the default base class for all Moose-using classes. When
127 you C<use Moose> in this class, your class will inherit from this
130 It provides a default constructor and destructor, which run the
131 C<BUILDALL> and C<DEMOLISHALL> methods respectively.
133 You don't actually I<need> to inherit from this in order to use Moose,
134 but it makes it easier to take advantage of all of Moose's features.
140 =item B<< Moose::Object->new(%params) >>
142 This method calls C<< $class->BUILDARGS(@_) >>, and then creates a new
143 instance of the appropriate class. Once the instance is created, it
144 calls C<< $instance->BUILDALL($params) >>.
146 =item B<< Moose::Object->BUILDARGS(%params) >>
148 The default implementation of this method accepts a hash or hash
149 reference of named parameters. If it receives a single argument that
150 I<isn't> a hash reference it throws an error.
152 You can override this method in your class to handle other types of
153 options passed to the constructor.
155 This method should always return a hash reference of named options.
157 =item B<< $object->BUILDALL($params) >>
159 This method will call every C<BUILD> method in the inheritance
160 hierarchy, starting with the most distant parent class and ending with
163 The C<BUILD> method will be passed the hash reference returned by
166 =item B<< $object->DEMOLISHALL >>
168 This will call every C<DEMOLISH> method in the inheritance hierarchy,
169 starting with the object's class and ending with the most distant
172 =item B<< $object->does($role_name) >>
174 This returns true if the object does the given role.
176 =item B<DOES ($class_or_role_name)>
178 This is a a Moose role-aware implementation of L<UNIVERSAL/DOES>.
180 This is effectively the same as writing:
182 $object->does($name) || $object->isa($name)
184 This method will work with Perl 5.8, which did not implement
187 =item B<< $object->dump($maxdepth) >>
189 This is a handy utility for C<Data::Dumper>ing an object. By default,
190 the maximum depth is 1, to avoid making a mess.
196 All complex software has bugs lurking in it, and this module is no
197 exception. If you find a bug please either email me, or add the bug
202 Stevan Little E<lt>stevan@iinteractive.comE<gt>
204 =head1 COPYRIGHT AND LICENSE
206 Copyright 2006-2009 by Infinity Interactive, Inc.
208 L<http://www.iinteractive.com>
210 This library is free software; you can redistribute it and/or modify
211 it under the same terms as Perl itself.