#!/usr/bin/perl # # Lgr.pm # # Controls both logging to a file and to the screen # you can set a verbosity for each independently # package Helper::Lgr; use strict; use warnings; use v5.10.0; use File::Basename; use File::Path qw(make_path); use FindBin; use Data::Dumper; my $script = basename( $0, '.pl', '.pm' ); # Logger is a classic singleton pattern. We only want one instance in our code my $instance = undef; sub getInstance { say "Get instance called from ".( caller ); if ($instance) { # Already instantiated, check if we need to change any settings say "Already instantiated"; return $instance; } else { say "Not yet instantiated"; } my $class = shift; my $instance = shift; # settings to use $instance = {} unless $instance; die "$instance is not a hash ref\n" unless ref $instance eq 'HASH'; bless $instance, $class; # we bless early so we can call methods on ourself ... And much more ...