2 package Moose::Meta::Method::Destructor;
8 use Scalar::Util 'blessed', 'weaken';
10 our $VERSION = '0.55_02';
11 $VERSION = eval $VERSION;
12 our $AUTHORITY = 'cpan:STEVAN';
14 use base 'Moose::Meta::Method',
15 'Class::MOP::Method::Generated';
21 (exists $options{options} && ref $options{options} eq 'HASH')
22 || confess "You must pass a hash of options";
24 ($options{package_name} && $options{name})
25 || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
30 'package_name' => $options{package_name},
31 'name' => $options{name},
33 'options' => $options{options},
34 'associated_metaclass' => $options{metaclass},
37 # we don't want this creating
38 # a cycle in the code, if not
40 weaken($self->{'associated_metaclass'});
42 $self->initialize_body;
49 sub options { (shift)->{'options'} }
50 sub associated_metaclass { (shift)->{'associated_metaclass'} }
56 # if called as a class method
57 # then must pass in a class name
58 unless (blessed $self) {
59 (blessed $_[0] && $_[0]->isa('Class::MOP::Class'))
60 || confess "When calling is_needed as a class method you must pass a class name";
61 return $_[0]->meta->can('DEMOLISH');
63 defined $self->{'body'} ? 1 : 0
69 # the %options should also include a both
70 # a call 'initializer' and call 'SUPER::'
71 # options, which should cover approx 90%
72 # of the possible use cases (even if it
73 # requires some adaption on the part of
74 # the author, after all, nothing is free)
76 my @DEMOLISH_methods = $self->associated_metaclass->find_all_methods_by_name('DEMOLISH');
78 return unless @DEMOLISH_methods;
83 foreach my $method (@DEMOLISH_methods) {
84 push @DEMOLISH_calls => '$_[0]->' . $method->{class} . '::DEMOLISH()';
87 $source .= join ";\n" => @DEMOLISH_calls;
89 $source .= ";\n" . '}';
90 warn $source if $self->options->{debug};
95 confess "Could not eval the destructor :\n\n$source\n\nbecause :\n\n$@" if $@;
97 $self->{'body'} = $code;
109 Moose::Meta::Method::Destructor - Method Meta Object for destructors
113 This is a subclass of L<Class::MOP::Method> which handles
114 constructing an approprate Destructor method. This is primarily
115 used in the making of immutable metaclasses, otherwise it is
116 not particularly useful.
126 =item B<meta_instance>
132 =item B<initialize_body>
134 =item B<associated_metaclass>
140 Stevan Little E<lt>stevan@iinteractive.comE<gt>
142 =head1 COPYRIGHT AND LICENSE
144 Copyright 2006-2008 by Infinity Interactive, Inc.
146 L<http://www.iinteractive.com>
148 This library is free software; you can redistribute it and/or modify
149 it under the same terms as Perl itself.