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.57';
13 $VERSION = eval $VERSION;
14 our $AUTHORITY = 'cpan:STEVAN';
18 my $params = $class->BUILDARGS(@_);
19 my $self = $class->meta->new_object($params);
20 $self->BUILDALL($params);
28 (ref($_[0]) eq 'HASH')
29 || confess "Single parameters to new() must be a HASH ref";
33 return {}; # FIXME this is compat behavior, but is it correct?
42 # NOTE: we ask Perl if we even
43 # need to do this first, to avoid
44 # extra meta level calls
45 return unless $_[0]->can('BUILD');
46 my ($self, $params) = @_;
47 foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) {
48 $method->{code}->body->($self, $params);
54 foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
55 $method->{code}->body->($self);
60 # NOTE: we ask Perl if we even
61 # need to do this first, to avoid
62 # extra meta level calls
63 return unless $_[0]->can('DEMOLISH');
64 # if we have an exception here ...
68 # run DEMOLISHALL ourselves, ...
73 # otherwise it is normal destruction
77 # support for UNIVERSAL::DOES ...
79 my $does = UNIVERSAL->can("DOES") ? "SUPER::DOES" : "isa";
81 my ( $self, $class_or_role_name ) = @_;
82 return $self->'.$does.'($class_or_role_name)
83 || $self->does($class_or_role_name);
87 # new does() methods will be created
88 # as approiate see Moose::Meta::Role
90 my ($self, $role_name) = @_;
92 || confess "You must supply a role name to does()";
93 my $meta = $self->meta;
94 foreach my $class ($meta->class_precedence_list) {
95 my $m = $meta->initialize($class);
97 if $m->can('does_role') && $m->does_role($role_name);
103 # Cmon, how many times have you written
104 # the following code while debugging:
107 # warn Dumper \%thing;
109 # It can get seriously annoying, so why
110 # not just do this ...
113 require Data::Dumper;
114 local $Data::Dumper::Maxdepth = shift if @_;
115 Data::Dumper::Dumper $self;
126 Moose::Object - The base object for Moose
130 This serves as the base object for all Moose classes. Every
131 effort will be made to ensure that all classes which C<use Moose>
132 will inherit from this class. It provides a default constructor
133 and destructor, which run all the BUILD and DEMOLISH methods in
136 You don't actually I<need> to inherit from this in order to
137 use Moose though. It is just here to make life easier.
145 This will return the metaclass associated with the given class.
149 This will call C<BUILDARGS>, create a new instance and call C<BUILDALL>.
153 This method processes an argument list into a hash reference. It is used by
158 This will call every C<BUILD> method in the inheritance hierarchy,
159 and pass it a hash-ref of the the C<%params> passed to C<new>.
163 This will call every C<DEMOLISH> method in the inheritance hierarchy.
165 =item B<does ($role_name)>
167 This will check if the invocant's class C<does> a given C<$role_name>.
168 This is similar to C<isa> for object, but it checks the roles instead.
170 =item B<DOES ($class_or_role_name)>
172 A Moose Role aware implementation of L<UNIVERSAL/DOES>.
174 C<DOES> is equivalent to C<isa> or C<does>.
176 =item B<dump ($maxdepth)>
178 Cmon, how many times have you written the following code while debugging:
183 It can get seriously annoying, so why not just use this.
189 All complex software has bugs lurking in it, and this module is no
190 exception. If you find a bug please either email me, or add the bug
195 Stevan Little E<lt>stevan@iinteractive.comE<gt>
197 =head1 COPYRIGHT AND LICENSE
199 Copyright 2006-2008 by Infinity Interactive, Inc.
201 L<http://www.iinteractive.com>
203 This library is free software; you can redistribute it and/or modify
204 it under the same terms as Perl itself.