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';
19 (exists $options{options} && ref $options{options} eq 'HASH')
20 || confess "You must pass a hash of options";
26 '%!options' => $options{options},
27 '$!associated_metaclass' => $options{metaclass},
30 # we don't want this creating
31 # a cycle in the code, if not
33 weaken($self->{'$!associated_metaclass'});
35 $self->intialize_body;
42 sub options { (shift)->{'%!options'} }
43 sub associated_metaclass { (shift)->{'$!associated_metaclass'} }
47 sub is_needed { defined $_[0]->{'&!body'} ? 1 : 0 }
52 # the %options should also include a both
53 # a call 'initializer' and call 'SUPER::'
54 # options, which should cover approx 90%
55 # of the possible use cases (even if it
56 # requires some adaption on the part of
57 # the author, after all, nothing is free)
61 foreach my $method ($self->associated_metaclass->find_all_methods_by_name('DEMOLISH')) {
62 push @DEMOLISH_calls => '$_[0]->' . $method->{class} . '::DEMOLISH()';
65 $source .= join "\n" => @DEMOLISH_calls;
67 $source .= ";\n" . '}';
68 warn $source if $self->options->{debug};
73 confess "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@" if $@;
75 $self->{'&!body'} = $code;
87 Moose::Meta::Method::Destructor - Method Meta Object for destructors
91 This is a subclass of L<Class::MOP::Method> which handles
92 constructing an approprate Destructor method. This is primarily
93 used in the making of immutable metaclasses, otherwise it is
94 not particularly useful.
104 =item B<meta_instance>
110 =item B<intialize_body>
112 =item B<associated_metaclass>
118 Stevan Little E<lt>stevan@iinteractive.comE<gt>
120 =head1 COPYRIGHT AND LICENSE
122 Copyright 2006, 2007 by Infinity Interactive, Inc.
124 L<http://www.iinteractive.com>
126 This library is free software; you can redistribute it and/or modify
127 it under the same terms as Perl itself.