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.50';
13 our $AUTHORITY = 'cpan:STEVAN';
18 my $meta = $class->meta;
21 (ref($_[0]) eq 'HASH')
22 || $meta->throw_error("Single parameters to new() must be a HASH ref", data => $_[0]);
29 my $self = $meta->new_object(%params);
30 $self->BUILDALL(\%params);
35 # NOTE: we ask Perl if we even
36 # need to do this first, to avoid
37 # extra meta level calls
38 return unless $_[0]->can('BUILD');
39 my ($self, $params) = @_;
40 foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) {
41 $method->{code}->body->($self, $params);
47 foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
48 $method->{code}->body->($self);
53 # NOTE: we ask Perl if we even
54 # need to do this first, to avoid
55 # extra meta level calls
56 return unless $_[0]->can('DEMOLISH');
57 # if we have an exception here ...
61 # run DEMOLISHALL ourselves, ...
66 # otherwise it is normal destruction
70 # new does() methods will be created
71 # as approiate see Moose::Meta::Role
73 my ($self, $role_name) = @_;
74 my $meta = $self->meta;
76 || $meta->throw_error("You much supply a role name to does()");
77 foreach my $class ($meta->class_precedence_list) {
78 my $m = $meta->initialize($class);
80 if $m->can('does_role') && $m->does_role($role_name);
86 # Cmon, how many times have you written
87 # the following code while debugging:
90 # warn Dumper \%thing;
92 # It can get seriously annoying, so why
93 # not just do this ...
97 local $Data::Dumper::Maxdepth = shift if @_;
98 Data::Dumper::Dumper $self;
109 Moose::Object - The base object for Moose
113 This serves as the base object for all Moose classes. Every
114 effort will be made to ensure that all classes which C<use Moose>
115 will inherit from this class. It provides a default constructor
116 and destructor, which run all the BUILD and DEMOLISH methods in
119 You don't actually I<need> to inherit from this in order to
120 use Moose though. It is just here to make life easier.
128 This will return the metaclass associated with the given class.
132 This will create a new instance and call C<BUILDALL>.
136 This will call every C<BUILD> method in the inheritance hierarchy,
137 and pass it a hash-ref of the the C<%params> passed to C<new>.
141 This will call every C<DEMOLISH> method in the inheritance hierarchy.
143 =item B<does ($role_name)>
145 This will check if the invocant's class C<does> a given C<$role_name>.
146 This is similar to C<isa> for object, but it checks the roles instead.
148 =item B<dump ($maxdepth)>
150 Cmon, how many times have you written the following code while debugging:
155 It can get seriously annoying, so why not just use this.
161 All complex software has bugs lurking in it, and this module is no
162 exception. If you find a bug please either email me, or add the bug
167 Stevan Little E<lt>stevan@iinteractive.comE<gt>
169 =head1 COPYRIGHT AND LICENSE
171 Copyright 2006-2008 by Infinity Interactive, Inc.
173 L<http://www.iinteractive.com>
175 This library is free software; you can redistribute it and/or modify
176 it under the same terms as Perl itself.