Skip to content

Instantly share code, notes, and snippets.

@twhaples
Created February 4, 2013 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twhaples/4708620 to your computer and use it in GitHub Desktop.
Save twhaples/4708620 to your computer and use it in GitHub Desktop.
This is an example of how imports in Perl do *not* work.
#! /usr/bin/perl
use strict;
use warnings qw(all);
package Foo;
BEGIN {
*Foo::pseudoimport = sub { printf "Cool beans!\n" };
}
sub fancysub {
pseudoimport();
}
sub normalsub {
printf "Boring beans.\n";
}
CHECK {
undef *Foo::pseudoimport;
}
package Main;
my $obj = bless {}, 'Foo';
$obj->normalsub;
$obj->fancysub;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment