cleaning up
[gitmo/Moose.git] / lib / Moose / Object.pm
index 6835bd2..2117e0e 100644 (file)
@@ -3,13 +3,35 @@ package Moose::Object;
 
 use strict;
 use warnings;
-use metaclass;
+use metaclass 'Moose::Meta::Class' => (
+       ':attribute_metaclass' => 'Moose::Meta::Attribute'
+);
+
+our $VERSION = '0.02';
 
 sub new {
-    my $class = shift;
-       $class->meta->new_object(@_);
+       my ($class, %params) = @_;
+       my $self = $class->meta->new_object(%params);
+       $self->BUILDALL(%params);
+       return $self;
+}
+
+sub BUILDALL {
+       my ($self, %params) = @_;
+       foreach my $method ($self->meta->find_all_methods_by_name('BUILD')) {
+               $method->{code}->($self, %params);
+       }
+}
+
+sub DEMOLISHALL {
+       my $self = shift;
+       foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
+               $method->{code}->($self);
+       }       
 }
 
+sub DESTROY { goto &DEMOLISHALL }
+
 1;
 
 __END__
@@ -18,9 +40,9 @@ __END__
 
 =head1 NAME
 
-Moose::Object - 
+Moose::Object - The base object for Moose
 
-=head1 SYNOPSIS
+=head1 SYNOPSIS 
 
 =head1 DESCRIPTION
 
@@ -32,6 +54,18 @@ Moose::Object -
 
 =item B<new>
 
+This will create a new instance and call C<BUILDALL>.
+
+=item B<BUILDALL>
+
+This will call every C<BUILD> method in the inheritance hierarchy.
+
+=item B<DEMOLISHALL>
+
+This will call every C<DEMOLISH> method in the inheritance hierarchy.
+
+=item B<NEXT>
+
 =back
 
 =head1 BUGS
@@ -40,13 +74,6 @@ All complex software has bugs lurking in it, and this module is no
 exception. If you find a bug please either email me, or add the bug
 to cpan-RT.
 
-=head1 CODE COVERAGE
-
-I use L<Devel::Cover> to test the code coverage of my tests, below is the 
-L<Devel::Cover> report on this module's test suite.
-
-=head1 ACKNOWLEDGEMENTS
-
 =head1 AUTHOR
 
 Stevan Little E<lt>stevan@iinteractive.comE<gt>