Commit | Line | Data |
fcd84ca9 |
1 | |
2 | package Moose::Object; |
3 | |
4 | use strict; |
5 | use warnings; |
bc1e29b5 |
6 | use metaclass 'Moose::Meta::Class' => ( |
7 | ':attribute_metaclass' => 'Moose::Meta::Attribute' |
8 | ); |
9 | |
b6aed8b0 |
10 | our $VERSION = '0.02'; |
fcd84ca9 |
11 | |
12 | sub new { |
82168dbb |
13 | my ($class, %params) = @_; |
c0e30cf5 |
14 | my $self = $class->meta->new_object(%params); |
15 | $self->BUILDALL(%params); |
16 | return $self; |
fcd84ca9 |
17 | } |
18 | |
c0e30cf5 |
19 | sub BUILDALL { |
20 | my ($self, %params) = @_; |
6ba6d68c |
21 | foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) { |
5569c072 |
22 | $method->{code}->($self, %params); |
c0e30cf5 |
23 | } |
24 | } |
25 | |
26 | sub DEMOLISHALL { |
27 | my $self = shift; |
28 | foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) { |
5569c072 |
29 | $method->{code}->($self); |
c0e30cf5 |
30 | } |
31 | } |
32 | |
33 | sub DESTROY { goto &DEMOLISHALL } |
34 | |
fcd84ca9 |
35 | 1; |
36 | |
37 | __END__ |
38 | |
39 | =pod |
40 | |
41 | =head1 NAME |
42 | |
e522431d |
43 | Moose::Object - The base object for Moose |
fcd84ca9 |
44 | |
fcd84ca9 |
45 | =head1 DESCRIPTION |
46 | |
6ba6d68c |
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 | |
fcd84ca9 |
56 | =head1 METHODS |
57 | |
58 | =over 4 |
59 | |
60 | =item B<meta> |
61 | |
6ba6d68c |
62 | This will return the metaclass associated with the given class. |
63 | |
fcd84ca9 |
64 | =item B<new> |
65 | |
e522431d |
66 | This will create a new instance and call C<BUILDALL>. |
67 | |
c0e30cf5 |
68 | =item B<BUILDALL> |
69 | |
e522431d |
70 | This will call every C<BUILD> method in the inheritance hierarchy. |
71 | |
c0e30cf5 |
72 | =item B<DEMOLISHALL> |
73 | |
e522431d |
74 | This will call every C<DEMOLISH> method in the inheritance hierarchy. |
75 | |
fcd84ca9 |
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 | |
fcd84ca9 |
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 |