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