Instance/object variables can be defined outside a constructor if something approaching the flyweight pattern is adopted...
package MyPkg;
my @Instances; # Visibility restricted to package by lexical declarati
+on
sub new {
my $self = shift;
my $opts = ref $_[0] ? shift : { @_ };
push @Instances, { %$opts };
return bless \(my $me = $#Instances), $self;
}
sub getScore {
my $self = shift;
return $Instances[$$self]->{score};
}
As for class methods, all subs declared in a package are, by definition, class methods since the package is the equivalent of a class. The invocation context is determined in the subs/methods themselves e.g.
package SomeClass;
sub classMethod {
my $self = shift;
die("Not an object/instance method") if ref $self;
.
.
}
sub objMethod {
my $self = shift;
die("Not an class method") unless ref $self;
.
.
}
Once again, just my 10 penn'orth FWIW, hope it's of interest/use to you
A user level that continues to overstate my experience :-))