Skip to content

Instantly share code, notes, and snippets.

@pjlsergeant
Created June 29, 2012 14:27
Show Gist options
  • Select an option

  • Save pjlsergeant/3018266 to your computer and use it in GitHub Desktop.

Select an option

Save pjlsergeant/3018266 to your computer and use it in GitHub Desktop.
Lazy constructors
package Acme::LazyConstruct;
use strict;
use warnings;
sub import {
my $pkg = caller(0);
$pkg = "main::$pkg" unless $pkg =~ m/::/;
eval "sub $pkg { $pkg->new }"; die $@ if $@;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment