7 use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class';
8 use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class';
10 our $VERSION = '0.73';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
16 my $params = $class->BUILDARGS(@_);
17 my $self = $class->meta->new_object($params);
18 $self->BUILDALL($params);
24 if ( scalar @_ == 1 ) {
25 unless ( defined $_[0] && ref $_[0] eq 'HASH' ) {
26 $class->meta->throw_error(
27 "Single parameters to new() must be a HASH ref",
30 return { %{ $_[0] } };
38 # NOTE: we ask Perl if we even
39 # need to do this first, to avoid
40 # extra meta level calls
41 return unless $_[0]->can('BUILD');
42 my ($self, $params) = @_;
43 foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) {
44 $method->{code}->execute($self, $params);
50 # NOTE: we ask Perl if we even
51 # need to do this first, to avoid
52 # extra meta level calls
53 return unless $self->can('DEMOLISH');
54 foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
55 $method->{code}->execute($self);
60 # if we have an exception here ...
64 # run DEMOLISHALL ourselves, ...
69 # otherwise it is normal destruction
73 # support for UNIVERSAL::DOES ...
75 my $does = UNIVERSAL->can("DOES") ? "SUPER::DOES" : "isa";
77 my ( $self, $class_or_role_name ) = @_;
78 return $self->'.$does.'($class_or_role_name)
79 || $self->does($class_or_role_name);
83 # new does() methods will be created
84 # as appropiate see Moose::Meta::Role
86 my ($self, $role_name) = @_;
87 my $meta = $self->meta;
89 || $meta->throw_error("You much supply a role name to does()");
90 foreach my $class ($meta->class_precedence_list) {
91 my $m = $meta->initialize($class);
93 if $m->can('does_role') && $m->does_role($role_name);
100 require Data::Dumper;
101 local $Data::Dumper::Maxdepth = shift if @_;
102 Data::Dumper::Dumper $self;
113 Moose::Object - The base object for Moose
117 This class is the default base class for all Moose-using classes. When
118 you C<use Moose> in this class, your class will inherit from this
121 It provides a default constructor and destructor, which run the
122 C<BUILDALL> and C<DEMOLISHALL> methods respectively.
124 You don't actually I<need> to inherit from this in order to use Moose,
125 but it makes it easier to take advantage of all of Moose's features.
131 =item B<< Moose::Object->new(%params) >>
133 This method calls C<< $class->BUILDARGS(@_) >>, and then creates a new
134 instance of the appropriate class. Once the instance is created, it
135 calls C<< $instance->BUILDALL($params) >>.
137 =item B<< Moose::Object->BUILDARGS(%params) >>
139 The default implementation of this method accepts a hash or hash
140 reference of named parameters. If it receives a single argument that
141 I<isn't> a hash reference it throws an error.
143 You can override this method in your class to handle other types of
144 options passed to the constructor.
146 This method should always return a hash reference of named options.
148 =item B<< $object->BUILDALL($params) >>
150 This method will call every C<BUILD> method in the inheritance
151 hierarchy, starting with the most distant parent class and ending with
154 The C<BUILD> method will be passed the hash reference returned by
157 =item B<< $object->DEMOLISHALL >>
159 This will call every C<DEMOLISH> method in the inheritance hierarchy,
160 starting with the object's class and ending with the most distant
163 =item B<< $object->does($role_name) >>
165 This returns true if the object does the given role.
167 =item B<DOES ($class_or_role_name)>
169 This is a a Moose role-aware implementation of L<UNIVERSAL/DOES>.
171 This is effectively the same as writing:
173 $object->does($name) || $object->isa($name)
175 This method will work with Perl 5.8, which did not implement
178 =item B<< $object->dump($maxdepth) >>
180 This is a handy utility for C<Data::Dumper>ing an object. By default,
181 the maximum depth is 1, to avoid making a mess.
187 All complex software has bugs lurking in it, and this module is no
188 exception. If you find a bug please either email me, or add the bug
193 Stevan Little E<lt>stevan@iinteractive.comE<gt>
195 =head1 COPYRIGHT AND LICENSE
197 Copyright 2006-2009 by Infinity Interactive, Inc.
199 L<http://www.iinteractive.com>
201 This library is free software; you can redistribute it and/or modify
202 it under the same terms as Perl itself.