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.72';
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 serves as the base object for all Moose classes. Every
118 effort will be made to ensure that all classes which C<use Moose>
119 will inherit from this class. It provides a default constructor
120 and destructor, which run all the BUILD and DEMOLISH methods in
123 You don't actually I<need> to inherit from this in order to
124 use Moose though. It is just here to make life easier.
132 This will return the metaclass associated with the given class.
136 This will call C<BUILDARGS>, create a new instance and call C<BUILDALL>.
140 This method processes an argument list into a hash reference. It is used by
145 This will call every C<BUILD> method in the inheritance hierarchy,
146 and pass it a hash-ref of the the C<%params> passed to C<new>.
150 This will call every C<DEMOLISH> method in the inheritance hierarchy.
152 =item B<does ($role_name)>
154 This will check if the invocant's class C<does> a given C<$role_name>.
155 This is similar to C<isa> for object, but it checks the roles instead.
157 =item B<DOES ($class_or_role_name)>
159 A Moose Role aware implementation of L<UNIVERSAL/DOES>.
161 C<DOES> is equivalent to C<isa> or C<does>.
163 =item B<dump ($maxdepth)>
165 C'mon, how many times have you written the following code while debugging:
170 It can get seriously annoying, so why not just use this.
176 All complex software has bugs lurking in it, and this module is no
177 exception. If you find a bug please either email me, or add the bug
182 Stevan Little E<lt>stevan@iinteractive.comE<gt>
184 =head1 COPYRIGHT AND LICENSE
186 Copyright 2006-2009 by Infinity Interactive, Inc.
188 L<http://www.iinteractive.com>
190 This library is free software; you can redistribute it and/or modify
191 it under the same terms as Perl itself.