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 { |
bdabd620 |
41 | my ($self, $role_name) = @_; |
0677220d |
42 | (defined $role_name) |
43 | || confess "You much supply a role name to does()"; |
bdabd620 |
44 | my $meta = $self->meta; |
45 | foreach my $class ($meta->class_precedence_list) { |
46 | return 1 |
47 | if $meta->initialize($class)->does_role($role_name); |
48 | } |
49 | return 0; |
0677220d |
50 | } |
ef333f17 |
51 | |
fcd84ca9 |
52 | 1; |
53 | |
54 | __END__ |
55 | |
56 | =pod |
57 | |
58 | =head1 NAME |
59 | |
e522431d |
60 | Moose::Object - The base object for Moose |
fcd84ca9 |
61 | |
fcd84ca9 |
62 | =head1 DESCRIPTION |
63 | |
6ba6d68c |
64 | This serves as the base object for all Moose classes. Every |
65 | effort will be made to ensure that all classes which C<use Moose> |
66 | will inherit from this class. It provides a default constructor |
67 | and destructor, which run all the BUILD and DEMOLISH methods in |
68 | the class tree. |
69 | |
70 | You don't actually I<need> to inherit from this in order to |
71 | use Moose though. It is just here to make life easier. |
72 | |
fcd84ca9 |
73 | =head1 METHODS |
74 | |
75 | =over 4 |
76 | |
77 | =item B<meta> |
78 | |
6ba6d68c |
79 | This will return the metaclass associated with the given class. |
80 | |
fcd84ca9 |
81 | =item B<new> |
82 | |
e522431d |
83 | This will create a new instance and call C<BUILDALL>. |
84 | |
c0e30cf5 |
85 | =item B<BUILDALL> |
86 | |
d7f17ebb |
87 | This will call every C<BUILD> method in the inheritance hierarchy, |
88 | and pass it a hash-ref of the the C<%params> passed to C<new>. |
e522431d |
89 | |
c0e30cf5 |
90 | =item B<DEMOLISHALL> |
91 | |
e522431d |
92 | This will call every C<DEMOLISH> method in the inheritance hierarchy. |
93 | |
ef333f17 |
94 | =item B<does ($role_name)> |
95 | |
fcd84ca9 |
96 | =back |
97 | |
98 | =head1 BUGS |
99 | |
100 | All complex software has bugs lurking in it, and this module is no |
101 | exception. If you find a bug please either email me, or add the bug |
102 | to cpan-RT. |
103 | |
fcd84ca9 |
104 | =head1 AUTHOR |
105 | |
106 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
107 | |
108 | =head1 COPYRIGHT AND LICENSE |
109 | |
110 | Copyright 2006 by Infinity Interactive, Inc. |
111 | |
112 | L<http://www.iinteractive.com> |
113 | |
114 | This library is free software; you can redistribute it and/or modify |
115 | it under the same terms as Perl itself. |
116 | |
117 | =cut |