Skip to content

Instantly share code, notes, and snippets.

@rightgo09
Created April 9, 2012 13:32
Show Gist options
  • Save rightgo09/2343432 to your computer and use it in GitHub Desktop.
Save rightgo09/2343432 to your computer and use it in GitHub Desktop.
To use "class" instead of "package"
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