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