package Image::Magick::Exceptions; use warnings; use strict; use Exception::Class qw/Image::Magick::Exception/; { no strict; no warnings qw/redefine prototype/; my $class = "Image::Magick"; for my $method (keys %{$class."::"}) { my $cmethod = "${class}::$method"; if ( defined *{$cmethod}{CODE} and $method ne 'new' and $method !~ /^[A-Z]+$/ ) { *{"hidden::$cmethod"} = *{$cmethod}{CODE}; *{$cmethod} = sub { my $err = &{"hidden::$cmethod"}; if("$err") { Image::Magick::Exception->throw (error => "$err"); }; $err; }; } } } package main; use Image::Magick; use Image::Magick::Exceptions; etc();