alpha has asked for the wisdom of the Perl Monks concerning the following question:
# class.pm package class; use 5.014; use strict; use warnings; use autodie; sub new {bless {}, 'class'} sub talk {print "111513\n"} # code.pl #!/usr/bin/env perl use strict; use warnings; use autodie; use 5.014; use Data::Dumper; BEGIN { $^P |= 0x10; eval 'sub DB::sub' if $] < 5.008007; } sub _unload_subs { my $file = shift || return; for my $sym ( grep { index( $_, "$file:" ) == 0 } keys %DB::sub ) +{ eval { undef &$sym }; warn "$sym: $@\n" if $@; delete $DB::sub{$sym}; } return 1; } do './class.pm'; my $obj = class->new(); $obj->talk; delete $INC{'./class.pm'}; _unload_subs('class'); #say Dumper \%DB::sub; my $dummy = <>; # we change class.pm meanwhile do './class.pm'; say $@ if $@; $obj = class->new(); $obj->talk; # results: # $ ./code.pl # 111513 # # panic: attempt to copy freed scalar 12dcbf0 to 1414870 at ./class.pm + line 3, <> line 1. # # Undefined subroutine &class::new called at ./code.pl line 38, <> lin +e 1. # Removing "use 5.014" from class.pm fixes the panic but is there a be +tter fix? # Also, why is this panic error happening?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reloading a module at run time
by tobyink (Canon) on Jan 16, 2013 at 09:45 UTC | |
by alpha (Scribe) on Jan 16, 2013 at 09:54 UTC |