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