#!/usr/bin/perl -w use strict; use warnings; BEGIN { sub sigwarn { print "[MYHANDLER] ".$_[0]; } sub sigdie { print "[MYHANDLER] ".$_[0]; exit(99); } $SIG{__WARN__} = \&sigwarn; $SIG{__DIE__} = \&sigdie; } load_module('Storable'); print "This script sucks\n"; sub load_module { # eg: load_module('CGI',0,[qw(:all)]) my $class = shift || return; my $silent = shift || 0; my $import = shift || 0; # an arrayref if you have to import(PARAM), else: just a bool. (my $file = $class) =~ s[::][/]g; local $SIG{__DIE__}; eval {require "$file.pm"}; if ($@) { return if $silent; sigdie("Error loading module '$class': $@"); } # do import if $import return $class; }