7 use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class';
8 use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class';
12 our $VERSION = '0.54';
13 our $AUTHORITY = 'cpan:STEVAN';
17 my $params = $class->BUILDARGS(@_);
18 my $self = $class->meta->new_object(%$params);
19 $self->BUILDALL($params);
27 (ref($_[0]) eq 'HASH')
28 || confess "Single parameters to new() must be a HASH ref";
32 return {}; # FIXME this is compat behavior, but is it correct?
41 # NOTE: we ask Perl if we even
42 # need to do this first, to avoid
43 # extra meta level calls
44 return unless $_[0]->can('BUILD');
45 my ($self, $params) = @_;
46 foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) {
47 $method->{code}->body->($self, $params);
53 foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
54 $method->{code}->body->($self);
59 # NOTE: we ask Perl if we even
60 # need to do this first, to avoid
61 # extra meta level calls
62 return unless $_[0]->can('DEMOLISH');
63 # if we have an exception here ...
67 # run DEMOLISHALL ourselves, ...
72 # otherwise it is normal destruction
76 # support for UNIVERSAL::DOES ...
78 my $does = UNIVERSAL->can("DOES") ? "SUPER::DOES" : "isa";
80 my ( $self, $class_or_role_name ) = @_;
81 return $self->'.$does.'($class_or_role_name)
82 || $self->does($class_or_role_name);
86 # new does() methods will be created
87 # as approiate see Moose::Meta::Role
89 my ($self, $role_name) = @_;
91 || confess "You must supply a role name to does()";
92 my $meta = $self->meta;
93 foreach my $class ($meta->class_precedence_list) {
94 my $m = $meta->initialize($class);
96 if $m->can('does_role') && $m->does_role($role_name);
102 # Cmon, how many times have you written
103 # the following code while debugging:
106 # warn Dumper \%thing;
108 # It can get seriously annoying, so why
109 # not just do this ...
112 require Data::Dumper;
113 local $Data::Dumper::Maxdepth = shift if @_;
114 Data::Dumper::Dumper $self;
125 Moose::Object - The base object for Moose
129 This serves as the base object for all Moose classes. Every
130 effort will be made to ensure that all classes which C<use Moose>
131 will inherit from this class. It provides a default constructor
132 and destructor, which run all the BUILD and DEMOLISH methods in
135 You don't actually I<need> to inherit from this in order to
136 use Moose though. It is just here to make life easier.
144 This will return the metaclass associated with the given class.
148 This will call C<BUILDARGS>, create a new instance and call C<BUILDALL>.
152 This method processes an argument list into a hash reference. It is used by
157 This will call every C<BUILD> method in the inheritance hierarchy,
158 and pass it a hash-ref of the the C<%params> passed to C<new>.
162 This will call every C<DEMOLISH> method in the inheritance hierarchy.
164 =item B<does ($role_name)>
166 This will check if the invocant's class C<does> a given C<$role_name>.
167 This is similar to C<isa> for object, but it checks the roles instead.
169 =item B<DOES ($class_or_role_name)>
171 A Moose Role aware implementation of L<UNIVERSAL/DOES>.
173 C<DOES> is equivalent to C<isa> or C<does>.
175 =item B<dump ($maxdepth)>
177 Cmon, how many times have you written the following code while debugging:
182 It can get seriously annoying, so why not just use this.
188 All complex software has bugs lurking in it, and this module is no
189 exception. If you find a bug please either email me, or add the bug
194 Stevan Little E<lt>stevan@iinteractive.comE<gt>
196 =head1 COPYRIGHT AND LICENSE
198 Copyright 2006-2008 by Infinity Interactive, Inc.
200 L<http://www.iinteractive.com>
202 This library is free software; you can redistribute it and/or modify
203 it under the same terms as Perl itself.