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