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