Created
June 29, 2012 14:27
-
-
Save pjlsergeant/3018266 to your computer and use it in GitHub Desktop.
Lazy constructors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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