package Foo; use strict; use warnings; sub new { my $class = shift; $self = bless {@_}, $class; $self->init_logging(); } sub init_logging { my $self = shift; return if exists $self->{LOGGER}; eval { require SomeLogger; $self->{LOGGER} = SomeLogger->new(); }; } sub debug { my $self = shift; return unless exists $self->{LOGGER}; $self->{LOGGER}->debug(@_); }