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