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