- or download this
my $instance1 = MyModule::new('1.0');
print $instance1->version();
...
my $instance2 = MyModule::new('2.0');
print $instance2->version();
#prints '2.0';
- or download this
package MyModule;
our $VERSION = '2.0';
our $vers = {'1.0'=>{__PACKAGE__.'::version'=>\&version_1_0},
'2.0'=>{__PACKAGE__.'::version'=>\&version_2_0}};
- or download this
sub new {
my $class = __PACKAGE__;
my $version = shift || $VERSION;
return bless({methods=>$$vers{$version}},$class);
}
- or download this
sub AUTOLOAD {
my $self = $_[0];
return &{$$self{methods}{$AUTOLOAD}}(@_);
}