Commit | Line | Data |
---|---|---|
c3398f5b | 1 | package Mouse::Object; |
007481ba | 2 | use Mouse::Util qw(does dump meta); # enables strict and warnings |
6d28c5cf | 3 | |
af04626d | 4 | sub new; |
c3398f5b | 5 | |
c3398f5b | 6 | sub BUILDALL { |
7 | my $self = shift; | |
8 | ||
9 | # short circuit | |
10 | return unless $self->can('BUILD'); | |
11 | ||
2230a6a3 | 12 | for my $class (reverse $self->meta->linearized_isa) { |
5124b717 | 13 | my $build = Mouse::Util::get_code_ref($class, 'BUILD') |
14 | || next; | |
7ca5c5fb | 15 | |
16 | $self->$build(@_); | |
c3398f5b | 17 | } |
3a63a2e7 | 18 | return; |
c3398f5b | 19 | } |
20 | ||
21 | sub DEMOLISHALL { | |
22 | my $self = shift; | |
23 | ||
24 | # short circuit | |
25 | return unless $self->can('DEMOLISH'); | |
26 | ||
8536d351 | 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 ;) | |
c26e296a | 31 | |
8536d351 | 32 | foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) { |
5124b717 | 33 | my $demolish = Mouse::Util::get_code_ref($class, 'DEMOLISH') |
34 | || next; | |
7ca5c5fb | 35 | |
36 | $self->$demolish(); | |
c3398f5b | 37 | } |
3a63a2e7 | 38 | return; |
c3398f5b | 39 | } |
40 | ||
41 | 1; | |
c3398f5b | 42 | __END__ |
43 | ||
44 | =head1 NAME | |
45 | ||
bedd575c | 46 | Mouse::Object - The base object for Mouse classes |
c3398f5b | 47 | |
a25ca8d6 | 48 | =head1 VERSION |
49 | ||
5176a3e4 | 50 | This document describes Mouse version 0.42 |
a25ca8d6 | 51 | |
c3398f5b | 52 | =head1 METHODS |
53 | ||
31c5194b | 54 | =head2 C<< new (Arguments) -> Object >> |
c3398f5b | 55 | |
1820fffe | 56 | Instantiates a new C<Mouse::Object>. This is obviously intended for subclasses. |
c3398f5b | 57 | |
31c5194b | 58 | =head2 C<< BUILDARGS (Arguments) -> HashRef >> |
c3398f5b | 59 | |
1820fffe | 60 | Lets you override the arguments that C<new> takes. Return a hashref of |
61 | parameters. | |
c3398f5b | 62 | |
31c5194b | 63 | =head2 C<< BUILDALL (\%args) >> |
c3398f5b | 64 | |
1820fffe | 65 | Calls C<BUILD> on each class in the class hierarchy. This is called at the |
66 | end of C<new>. | |
c3398f5b | 67 | |
31c5194b | 68 | =head2 C<< BUILD (\%args) >> |
442125dc | 69 | |
1820fffe | 70 | You may put any business logic initialization in BUILD methods. You don't |
71 | need to redispatch or return any specific value. | |
442125dc | 72 | |
1820fffe | 73 | =head2 C<< DEMOLISHALL >> |
c3398f5b | 74 | |
1820fffe | 75 | Calls C<DEMOLISH> on each class in the class hierarchy. This is called at |
76 | C<DESTROY> time. | |
c3398f5b | 77 | |
1820fffe | 78 | =head2 C<< DEMOLISH >> |
c3398f5b | 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 | ||
df963a63 | 83 | |
1820fffe | 84 | =head2 C<< does ($role_name) -> Bool >> |
56a558f9 | 85 | |
1820fffe | 86 | This will check if the invocant's class B<does> a given C<$role_name>. |
56a558f9 | 87 | This is similar to "isa" for object, but it checks the roles instead. |
88 | ||
1820fffe | 89 | =head2 C<<dump ($maxdepth) -> Str >> |
df963a63 | 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 | ||
1820fffe | 102 | =head1 SEE ALSO |
103 | ||
104 | L<Moose::Object> | |
c3398f5b | 105 | |
1820fffe | 106 | =cut |
df963a63 | 107 |