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