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 | |
ef333f17 |
10 | our $VERSION = '0.04'; |
fcd84ca9 |
11 | |
12 | sub new { |
05d9eaf6 |
13 | my $class = shift; |
14 | my %params = (scalar @_ == 1) ? %{$_[0]} : @_; |
c0e30cf5 |
15 | my $self = $class->meta->new_object(%params); |
d7f17ebb |
16 | $self->BUILDALL(\%params); |
c0e30cf5 |
17 | return $self; |
fcd84ca9 |
18 | } |
19 | |
c0e30cf5 |
20 | sub BUILDALL { |
d7f17ebb |
21 | my ($self, $params) = @_; |
6ba6d68c |
22 | foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) { |
d7f17ebb |
23 | $method->{code}->($self, $params); |
c0e30cf5 |
24 | } |
25 | } |
26 | |
27 | sub DEMOLISHALL { |
28 | my $self = shift; |
29 | foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) { |
5569c072 |
30 | $method->{code}->($self); |
c0e30cf5 |
31 | } |
32 | } |
33 | |
34 | sub DESTROY { goto &DEMOLISHALL } |
35 | |
ef333f17 |
36 | # new does() methods will be created |
37 | # as approiate see Moose::Meta::Role |
38 | sub does { 0 } |
39 | |
fcd84ca9 |
40 | 1; |
41 | |
42 | __END__ |
43 | |
44 | =pod |
45 | |
46 | =head1 NAME |
47 | |
e522431d |
48 | Moose::Object - The base object for Moose |
fcd84ca9 |
49 | |
fcd84ca9 |
50 | =head1 DESCRIPTION |
51 | |
6ba6d68c |
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 | |
fcd84ca9 |
61 | =head1 METHODS |
62 | |
63 | =over 4 |
64 | |
65 | =item B<meta> |
66 | |
6ba6d68c |
67 | This will return the metaclass associated with the given class. |
68 | |
fcd84ca9 |
69 | =item B<new> |
70 | |
e522431d |
71 | This will create a new instance and call C<BUILDALL>. |
72 | |
c0e30cf5 |
73 | =item B<BUILDALL> |
74 | |
d7f17ebb |
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>. |
e522431d |
77 | |
c0e30cf5 |
78 | =item B<DEMOLISHALL> |
79 | |
e522431d |
80 | This will call every C<DEMOLISH> method in the inheritance hierarchy. |
81 | |
ef333f17 |
82 | =item B<does ($role_name)> |
83 | |
fcd84ca9 |
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 | |
fcd84ca9 |
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 |