BUGS
[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 {
bdabd620 41 my ($self, $role_name) = @_;
0677220d 42 (defined $role_name)
43 || confess "You much supply a role name to does()";
bdabd620 44 my $meta = $self->meta;
45 foreach my $class ($meta->class_precedence_list) {
46 return 1
47 if $meta->initialize($class)->does_role($role_name);
48 }
49 return 0;
0677220d 50}
ef333f17 51
fcd84ca9 521;
53
54__END__
55
56=pod
57
58=head1 NAME
59
e522431d 60Moose::Object - The base object for Moose
fcd84ca9 61
fcd84ca9 62=head1 DESCRIPTION
63
6ba6d68c 64This serves as the base object for all Moose classes. Every
65effort will be made to ensure that all classes which C<use Moose>
66will inherit from this class. It provides a default constructor
67and destructor, which run all the BUILD and DEMOLISH methods in
68the class tree.
69
70You don't actually I<need> to inherit from this in order to
71use Moose though. It is just here to make life easier.
72
fcd84ca9 73=head1 METHODS
74
75=over 4
76
77=item B<meta>
78
6ba6d68c 79This will return the metaclass associated with the given class.
80
fcd84ca9 81=item B<new>
82
e522431d 83This will create a new instance and call C<BUILDALL>.
84
c0e30cf5 85=item B<BUILDALL>
86
d7f17ebb 87This will call every C<BUILD> method in the inheritance hierarchy,
88and pass it a hash-ref of the the C<%params> passed to C<new>.
e522431d 89
c0e30cf5 90=item B<DEMOLISHALL>
91
e522431d 92This will call every C<DEMOLISH> method in the inheritance hierarchy.
93
ef333f17 94=item B<does ($role_name)>
95
fcd84ca9 96=back
97
98=head1 BUGS
99
100All complex software has bugs lurking in it, and this module is no
101exception. If you find a bug please either email me, or add the bug
102to cpan-RT.
103
fcd84ca9 104=head1 AUTHOR
105
106Stevan Little E<lt>stevan@iinteractive.comE<gt>
107
108=head1 COPYRIGHT AND LICENSE
109
110Copyright 2006 by Infinity Interactive, Inc.
111
112L<http://www.iinteractive.com>
113
114This library is free software; you can redistribute it and/or modify
115it under the same terms as Perl itself.
116
117=cut