Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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


Comment on Re: AutoLoader destroy issue
Download Code
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 AutoLoader.pm 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2015-07-31 11:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls