Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: AutoLoader destroy issue

by Khen1950fx (Canon)
on Aug 07, 2012 at 22:00 UTC ( #986090=note: print w/replies, xml ) Need Help??

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";

Replies are listed 'Best First'.
Re^2: AutoLoader destroy issue
by Anonymous Monk on Aug 07, 2012 at 22:30 UTC
    Hi Khen1950fx, thanks for your response. My AUTOLOAD is in and not in my own code. Do I need to define it in MyOwnTable or A or both ? I tried defining it in both A and MyOwnTable (like you did in CD::Music) along with the empty DESTROY subroutine, but I'm still receiving the error/warning. :( thanks, Michael

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986090]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2018-03-18 08:49 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (229 votes). Check out past polls.