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