use B::Deparse (); { # Fetch the original source code my $source_code = B::Deparse->new->coderef2text( \&HTML::TableExtract::TableState::_taste_text ); # Alter the source to include error trapping and the diagnostics $source_code = 'eval { ' . $source_code . ' }; print STDERR $@ if $@; die $@;'; $source_code =~ s/(\$self.*)$/$1 print "skew: ".\$self->_skew."\\n" . "_terminus_trigger: ".\$self->_terminus_trigger."\\n" . "_column_wanted: ".\$self->_column_wanted."\\n" . "umbrella: \$\$self{'umbrella'}\\n" . "text: q[\$text]\\n";\n/ or die "Source patch failed"; # (updated - added a package declaration per 'theorbtwo') # Create and assign the new method into place. *HTML::TableExtract::TableState::_taste_test = eval "sub { package HTML::TableExtract::TableState; $source_code; };" or die "Eval of \$source_code failed: $@\n$source_code"; }