in reply to Re: Carp::Clan
in thread Carp::Clan
my %handler; BEGIN { %handler = ( foo => sub { ref $_[0] eq 'ARRAY' or croak "foo key takes a hashre +f"; ... }, bar => sub { $_[0] =~ /wibble$/ or croak "bar key must end with 'w +ibble'"; ... }, ) } sub process_something { my %arg = @_; my @results; while( my ( $elem, $param ) = each %arg ) { push @results, $handler->{ $elem }->( $param ); } }
croak will say the error was in process_something, when you really want it to be thrown for the where the call to process_something was.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Carp::Clan
by ikegami (Patriarch) on Jun 08, 2006 at 21:37 UTC |