94a73d76ca42713a966e4408daf527fd220f0201
[gitmo/Mouse.git] / lib / Mouse / Object.pm
1 package Mouse::Object;
2 use Mouse::Util qw(does dump); # enables strict and warnings
3
4 sub new;
5
6
7 sub BUILDALL {
8     my $self = shift;
9
10     # short circuit
11     return unless $self->can('BUILD');
12
13     for my $class (reverse $self->meta->linearized_isa) {
14         my $build = Mouse::Util::get_code_ref($class, 'BUILD')
15             || next;
16
17         $self->$build(@_);
18     }
19     return;
20 }
21
22 sub DEMOLISHALL {
23     my $self = shift;
24
25     # short circuit
26     return unless $self->can('DEMOLISH');
27
28     # We cannot count on being able to retrieve a previously made
29     # metaclass, _or_ being able to make a new one during global
30     # destruction. However, we should still be able to use mro at
31     # that time (at least tests suggest so ;)
32
33     foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
34         my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH')
35             || next;
36
37         $self->$demolish();
38     }
39     return;
40 }
41
42 1;
43
44 __END__
45
46 =head1 NAME
47
48 Mouse::Object - The base object for Mouse classes
49
50 =head1 VERSION
51
52 This document describes Mouse version 0.40_05
53
54 =head1 METHODS
55
56 =head2 C<< new (Arguments) -> Object >>
57
58 Instantiates a new C<Mouse::Object>. This is obviously intended for subclasses.
59
60 =head2 C<< BUILDARGS (Arguments) -> HashRef >>
61
62 Lets you override the arguments that C<new> takes. Return a hashref of
63 parameters.
64
65 =head2 C<< BUILDALL (\%args) >>
66
67 Calls C<BUILD> on each class in the class hierarchy. This is called at the
68 end of C<new>.
69
70 =head2 C<< BUILD (\%args) >>
71
72 You may put any business logic initialization in BUILD methods. You don't
73 need to redispatch or return any specific value.
74
75 =head2 C<< DEMOLISHALL >>
76
77 Calls C<DEMOLISH> on each class in the class hierarchy. This is called at
78 C<DESTROY> time.
79
80 =head2 C<< DEMOLISH >>
81
82 You may put any business logic deinitialization in DEMOLISH methods. You don't
83 need to redispatch or return any specific value.
84
85
86 =head2 C<< does ($role_name) -> Bool >>
87
88 This will check if the invocant's class B<does> a given C<$role_name>.
89 This is similar to "isa" for object, but it checks the roles instead.
90
91 =head2 C<<dump ($maxdepth) -> Str >>
92
93 From the Moose POD:
94
95     C'mon, how many times have you written the following code while debugging:
96
97      use Data::Dumper; 
98      warn Dumper $obj;
99
100     It can get seriously annoying, so why not just use this.
101
102 The implementation was lifted directly from Moose::Object.
103
104 =head1 SEE ALSO
105
106 L<Moose::Object>
107
108 =cut
109