Add get_read_method_ref and get_write_method_ref. Remove get_read_method and get_writ...
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Destructor.pm
1 package Mouse::Meta::Method::Destructor;
2 use strict;
3 use warnings;
4
5 sub _empty_destroy{ }
6
7 sub _generate_destructor_method {
8     my ($class, $metaclass) = @_;
9
10     my $demolishall = do {
11         if ($metaclass->name->can('DEMOLISH')) {
12             my @code = ();
13             for my $class ($metaclass->linearized_isa) {
14                 no strict 'refs';
15                 if (*{$class . '::DEMOLISH'}{CODE}) {
16                     push @code, "${class}::DEMOLISH(\$self);";
17                 }
18             }
19             join "\n", @code;
20         } else {
21             $metaclass->add_method(DESTROY => \&_empty_destroy);
22             return;
23         }
24     };
25
26     my $destructor_name = $metaclass->name . '::DESTROY';
27     my $code = sprintf("#line %d %s\n", __LINE__, __FILE__) . <<"...";
28     sub $destructor_name \{
29         my \$self = shift;
30         $demolishall;
31     }
32 ...
33
34     my $e = do{
35         local $@;
36         eval $code;
37         $@;
38     };
39     die $@ if $@;
40     return;
41 }
42
43 1;