#! /usr/bin/env perl use strict; use warnings; use 5.020; package DB::Base { sub foo { my $self = shift; printf "%s: foo\n", ref($self); } sub bar { my $self = shift; printf "%s: bar\n", ref($self); } sub show_table { my $self = shift; printf "%s: %s\n", ref($self), $self->{table}; } }; package DB::Service { use base "DB::Base"; my $table = "service"; # DB::Service specific constructor sub new { my $class = shift; my %attr = @_; my $self = { table => $table, }; bless $self, ref($class)||$class; return $self; } }; package DB::Customer { use base "DB::Base"; my $table = "customer"; # DB::Customer specific constructor sub new { my $class = shift; my %attr = @_; my $self = { table => $table, }; bless $self, ref($class)||$class; return $self; } }; package main; my $customer = DB::Customer->new(); $customer->show_table(); my $service = DB::Service->new(); $service->show_table(); __END__;