2 package Moose::Meta::Method::Destructor;
8 use Scalar::Util 'blessed', 'weaken';
10 our $VERSION = '0.01';
11 our $AUTHORITY = 'cpan:STEVAN';
13 use base 'Moose::Meta::Method',
14 'Class::MOP::Method::Generated';
20 (exists $options{options} && ref $options{options} eq 'HASH')
21 || confess "You must pass a hash of options";
27 '%!options' => $options{options},
28 '$!associated_metaclass' => $options{metaclass},
31 # we don't want this creating
32 # a cycle in the code, if not
34 weaken($self->{'$!associated_metaclass'});
36 $self->intialize_body;
43 sub options { (shift)->{'%!options'} }
44 sub associated_metaclass { (shift)->{'$!associated_metaclass'} }
48 sub is_needed { defined $_[0]->{'&!body'} ? 1 : 0 }
53 # the %options should also include a both
54 # a call 'initializer' and call 'SUPER::'
55 # options, which should cover approx 90%
56 # of the possible use cases (even if it
57 # requires some adaption on the part of
58 # the author, after all, nothing is free)
62 foreach my $method ($self->associated_metaclass->find_all_methods_by_name('DEMOLISH')) {
63 push @DEMOLISH_calls => '$_[0]->' . $method->{class} . '::DEMOLISH()';
66 $source .= join "\n" => @DEMOLISH_calls;
68 $source .= ";\n" . '}';
69 warn $source if $self->options->{debug};
74 confess "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@" if $@;
76 $self->{'&!body'} = $code;
88 Moose::Meta::Method::Destructor - Method Meta Object for destructors
92 This is a subclass of L<Class::MOP::Method> which handles
93 constructing an approprate Destructor method. This is primarily
94 used in the making of immutable metaclasses, otherwise it is
95 not particularly useful.
105 =item B<meta_instance>
111 =item B<intialize_body>
113 =item B<associated_metaclass>
119 Stevan Little E<lt>stevan@iinteractive.comE<gt>
121 =head1 COPYRIGHT AND LICENSE
123 Copyright 2006-2008 by Infinity Interactive, Inc.
125 L<http://www.iinteractive.com>
127 This library is free software; you can redistribute it and/or modify
128 it under the same terms as Perl itself.