0_03
[gitmo/Moose.git] / lib / Moose / Object.pm
CommitLineData
fcd84ca9 1
2package Moose::Object;
3
4use strict;
5use warnings;
bc1e29b5 6use metaclass 'Moose::Meta::Class' => (
7 ':attribute_metaclass' => 'Moose::Meta::Attribute'
8);
9
b6aed8b0 10our $VERSION = '0.02';
fcd84ca9 11
12sub new {
82168dbb 13 my ($class, %params) = @_;
c0e30cf5 14 my $self = $class->meta->new_object(%params);
d7f17ebb 15 $self->BUILDALL(\%params);
c0e30cf5 16 return $self;
fcd84ca9 17}
18
c0e30cf5 19sub BUILDALL {
d7f17ebb 20 my ($self, $params) = @_;
6ba6d68c 21 foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) {
d7f17ebb 22 $method->{code}->($self, $params);
c0e30cf5 23 }
24}
25
26sub DEMOLISHALL {
27 my $self = shift;
28 foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
5569c072 29 $method->{code}->($self);
c0e30cf5 30 }
31}
32
33sub DESTROY { goto &DEMOLISHALL }
34
fcd84ca9 351;
36
37__END__
38
39=pod
40
41=head1 NAME
42
e522431d 43Moose::Object - The base object for Moose
fcd84ca9 44
fcd84ca9 45=head1 DESCRIPTION
46
6ba6d68c 47This serves as the base object for all Moose classes. Every
48effort will be made to ensure that all classes which C<use Moose>
49will inherit from this class. It provides a default constructor
50and destructor, which run all the BUILD and DEMOLISH methods in
51the class tree.
52
53You don't actually I<need> to inherit from this in order to
54use Moose though. It is just here to make life easier.
55
fcd84ca9 56=head1 METHODS
57
58=over 4
59
60=item B<meta>
61
6ba6d68c 62This will return the metaclass associated with the given class.
63
fcd84ca9 64=item B<new>
65
e522431d 66This will create a new instance and call C<BUILDALL>.
67
c0e30cf5 68=item B<BUILDALL>
69
d7f17ebb 70This will call every C<BUILD> method in the inheritance hierarchy,
71and pass it a hash-ref of the the C<%params> passed to C<new>.
e522431d 72
c0e30cf5 73=item B<DEMOLISHALL>
74
e522431d 75This will call every C<DEMOLISH> method in the inheritance hierarchy.
76
fcd84ca9 77=back
78
79=head1 BUGS
80
81All complex software has bugs lurking in it, and this module is no
82exception. If you find a bug please either email me, or add the bug
83to cpan-RT.
84
fcd84ca9 85=head1 AUTHOR
86
87Stevan Little E<lt>stevan@iinteractive.comE<gt>
88
89=head1 COPYRIGHT AND LICENSE
90
91Copyright 2006 by Infinity Interactive, Inc.
92
93L<http://www.iinteractive.com>
94
95This library is free software; you can redistribute it and/or modify
96it under the same terms as Perl itself.
97
98=cut