Skip to content

Instantly share code, notes, and snippets.

@kentfredric
Created October 28, 2009 12:28
Show Gist options
  • Save kentfredric/220449 to your computer and use it in GitHub Desktop.
Save kentfredric/220449 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use namespace::clean;
BEGIN {
my $symtab;
{
no strict 'refs';
$symtab = \%{'main::'};
}
last if ( exists $symtab->{'foo'} );
my $debugging = sub() { 0 };
if ( exists $ENV{'TEST_DEBUGGING'} ) {
$debugging = sub(){ 1 } if (( $ENV{'TEST_DEBUGGING'} + 0 ) > 0 );
}
{
no strict 'refs';
*{'main::foo'} = $debugging;
}
}
print '.' . foo . '/';
if (foo) {
print 1;
}
else {
print 0;
}
sub bar {
my %symtab;
{
no strict 'refs';
%symtab = %{'main::'};
}
if ( exists $symtab{'foo'} ) {
print 'exists';
}
print $symtab{'foo'}->();
print Dumper(\%symtab );
}
bar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment