package Ex::mod; use strict; use warnings; # package-scoped config. my %conf = ( user => undef, ); # config routine. NB: FP! # ::conf( 'key' => 'value' ); sub conf { my %c = ( @_ ); for (keys %c) { $conf{$_} = $c{$_} if exists $conf{$_}; } } # new(), the constructor. sub new { my $class = shift; $class = ref($class) || $class; # subclass boilerplate. my %opts = ( @_ ); my $self = { user => $opts{user} // $conf{user} // '', }; return bless $self, $class; } # whoami() - method to say who this object's user is: sub whoami { my $self = shift; return $self->{user} // undef; }