package ProcInfo; use Carp; use strict; use warnings; our $VERSION = '0.01'; sub new { my $class = shift; my $self = {}; bless $self, $class; $self->_init(); return $self; } sub _init { my $self = shift; my $osModule = "ProcInfo_$^O"; # Load the subclass if it isn't already loaded. eval "require $osModule"; if($@) { croak "Could not load OS ProcInfo Module:$osModule. [$@]"; } # rebless self using subclass. bless $self, $osModule; $self->_init(@_); return $self; } sub method_1 { return 1; } 1; #### package ProcInfo_linux; use strict; use warnings; use base qw|ProcInfo|; our $VERSION = '0.01'; sub _init { my $self = shift; return $self; } sub method_1 { return 1; } 1; #### use Test::More tests => 3; BEGIN { use_ok('ProcInfo') }; my $pInfo = new ProcInfo; is(ref($pInfo), "ProcInfo_$^O", "Factory new Works"); ok($pInfo->method_1());