my $obj = MyPackage->new("..."); # ... my @some_list = $obj->some_method("some string"); #### package MyPackage; use strict; use warnings; sub new { my $class = shift; $class eq __PACKAGE__ or die "oops: ctor unexpected '$class'"; my $name = shift; print "in ctor: '$class' (name=$name)\n"; my $self = {}; $self->{NAME} = $name; bless $self, $class; return $self; } sub some_instance_method { my $self = shift; my $param1 = shift; print "in some_instance_method: $self '$param1'\n"; return $self->{NAME}; } sub some_class_method { my $class = shift; my $param1 = shift; print "in some_class_method: '$class' ($param1)\n"; $class eq __PACKAGE__ or die "oops: unexpected '$class'"; return "hello from some class method"; } sub some_utility_method { my $param1 = shift; print "in some_utility_method: ($param1)\n"; return "hello from some utility method"; } 1; #### use strict; use warnings; use MyPackage; my $obj = MyPackage->new("John Smith"); my $name = $obj->some_instance_method(69); print "name='$name'\n"; my $cm = MyPackage->some_class_method(42); print "cm='$cm'\n"; my $um = MyPackage::some_utility_method(43); print "um='$um'\n"; #### in ctor: 'MyPackage' (name=John Smith) in some_instance_method: MyPackage=HASH(0x1c905b0) '69' name='John Smith' in some_class_method: 'MyPackage' (42) cm='hello from some class method' in some_utility_method: (43) um='hello from some utility method'