2 package Moose::Meta::Method::Destructor;
8 use Scalar::Util 'blessed', 'weaken';
10 our $VERSION = '0.03';
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";
23 ($options{package_name} && $options{name})
24 || confess "You must supply the package_name and name parameters";
29 '$!package_name' => $options{package_name},
30 '$!name' => $options{name},
32 '%!options' => $options{options},
33 '$!associated_metaclass' => $options{metaclass},
36 # we don't want this creating
37 # a cycle in the code, if not
39 weaken($self->{'$!associated_metaclass'});
41 $self->initialize_body;
48 sub options { (shift)->{'%!options'} }
49 sub associated_metaclass { (shift)->{'$!associated_metaclass'} }
53 sub is_needed { defined $_[0]->{'&!body'} ? 1 : 0 }
58 # the %options should also include a both
59 # a call 'initializer' and call 'SUPER::'
60 # options, which should cover approx 90%
61 # of the possible use cases (even if it
62 # requires some adaption on the part of
63 # the author, after all, nothing is free)
67 foreach my $method ($self->associated_metaclass->find_all_methods_by_name('DEMOLISH')) {
68 push @DEMOLISH_calls => '$_[0]->' . $method->{class} . '::DEMOLISH()';
71 $source .= join ";\n" => @DEMOLISH_calls;
73 $source .= ";\n" . '}';
74 warn $source if $self->options->{debug};
79 confess "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@" if $@;
81 $self->{'&!body'} = $code;
93 Moose::Meta::Method::Destructor - Method Meta Object for destructors
97 This is a subclass of L<Class::MOP::Method> which handles
98 constructing an approprate Destructor method. This is primarily
99 used in the making of immutable metaclasses, otherwise it is
100 not particularly useful.
110 =item B<meta_instance>
116 =item B<initialize_body>
118 =item B<associated_metaclass>
124 Stevan Little E<lt>stevan@iinteractive.comE<gt>
126 =head1 COPYRIGHT AND LICENSE
128 Copyright 2006-2008 by Infinity Interactive, Inc.
130 L<http://www.iinteractive.com>
132 This library is free software; you can redistribute it and/or modify
133 it under the same terms as Perl itself.