Created
April 9, 2012 13:32
-
-
Save rightgo09/2343432 to your computer and use it in GitHub Desktop.
To use "class" instead of "package"
This file contains 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 class; | |
use strict; | |
use warnings; | |
sub import { | |
no strict 'refs'; | |
my $class = caller; | |
*{"$class\::class"} = sub { | |
my $package = shift(@_); | |
# "new" method is created by default. | |
*{"$package\::new"} = sub { | |
my ($class, @args) = @_; | |
return bless { @args }, $class; | |
}; | |
while (@_) { | |
my $subname = shift(@_); | |
my $subroutine = shift(@_); | |
*{"$package\::$subname"} = $subroutine; | |
} | |
}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment