From: Rafael Garcia-Suarez Date: Mon, 15 Jan 2007 12:29:14 +0000 (+0000) Subject: Factorise croak() calls and error messages in feature.pm X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b42943c4698d2a49df050632f1dff2cff372ed52;p=p5sagit%2Fp5-mst-13.2.git Factorise croak() calls and error messages in feature.pm (suggested by Michael G Schwern) p4raw-id: //depot/perl@29815 --- diff --git a/lib/feature.pm b/lib/feature.pm index 238820e..4a828d2 100644 --- a/lib/feature.pm +++ b/lib/feature.pm @@ -105,27 +105,19 @@ to C. sub import { my $class = shift; if (@_ == 0) { - require Carp; - Carp->import("croak"); croak("No features specified"); } while (@_) { my $name = shift(@_); if ($name =~ /^:(.*)/) { if (!exists $feature_bundle{$1}) { - require Carp; - Carp->import("croak"); - croak(sprintf('Feature bundle "%s" is not supported by Perl %vd', - $1, $^V)); + unknown_feature_bundle($1); } unshift @_, @{$feature_bundle{$1}}; next; } if (!exists $feature{$name}) { - require Carp; - Carp->import("croak"); - croak(sprintf('Feature "%s" is not supported by Perl %vd', - $name, $^V)); + unknown_feature($name); } $^H{$feature{$name}} = 1; } @@ -144,19 +136,13 @@ sub unimport { my $name = shift; if ($name =~ /^:(.*)/) { if (!exists $feature_bundle{$1}) { - require Carp; - Carp->import("croak"); - croak(sprintf('Feature bundle "%s" is not supported by Perl %vd', - $1, $^V)); + unknown_feature_bundle($1); } unshift @_, @{$feature_bundle{$1}}; next; } if (!exists($feature{$name})) { - require Carp; - Carp->import("croak"); - croak(sprintf('Feature "%s" is not supported by Perl %vd', - $name, $^V)); + unknown_feature($name); } else { delete $^H{$feature{$name}}; @@ -164,4 +150,21 @@ sub unimport { } } +sub unknown_feature { + my $feature = shift; + croak(sprintf('Feature "%s" is not supported by Perl %vd', + $feature, $^V)); +} + +sub unknown_feature_bundle { + my $feature = shift; + croak(sprintf('Feature bundle "%s" is not supported by Perl %vd', + $feature, $^V)); +} + +sub croak { + require Carp; + Carp::croak(@_); +} + 1;