in reply to
AutoLoader destroy issue
Put an empty DESTROY subroutine after AUTOLOAD and the problem goes away.
#!perl -w
package CD::Music;
use strict;
use vars '$AUTOLOAD';
sub AUTOLOAD {
my ($self) = @_;
$AUTOLOAD =~ /.*::get(_\w+)/
or die "No such method: $AUTOLOAD";
exists $self->{$1}
or die "No such attribute: $1";
return $self->{$1}
}
sub DESTROY { }
{
my $_count = 0;
sub get_count { $_count }
my $_incr_count = sub { ++$_count };
sub new {
my ($class) = @_;
$_incr_count->();
bless {
_name => $_[1],
_artist => $_[2],
_publisher => $_[3],
_ISBN => $_[4],
_tracks => $_[5],
_room => $_[6],
_shelf => $_[7],
_rating => $_[8],
}, $class;
}
sub get_location { ($_[0]->{_room}, $_[0]->{_shelf}) }
sub set_location {
my ($self, $shelf, $room) = @_;
$self->{_room} = $room if $room;
$self->{_shelf} = $shelf if $shelf;
return ($self->{_room}, $self->{_shelf});
}
sub set_rating {
my ($self, $rating) = @_;
$self->{_rating} = $rating if defined $rating;
return $self->{_rating};
}
}
package main;
my $cd = CD::Music->new( "Canon in D", "Pachelbel", "Boering Mu\u00df
+GmbH", "1729-67836847-1", 1, 8, 8, 5.0);
print $cd->get_name, ", ", $cd->get_publisher, "\n";
printf "Room %s, shelf %s\n", $cd->get_location;
$cd->set_location(5,3);
print CD::Music->get_count, "\n";