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