summaryrefslogtreecommitdiff
path: root/lib/feature.pm
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-01-15 12:29:14 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-01-15 12:29:14 +0000
commitb42943c4698d2a49df050632f1dff2cff372ed52 (patch)
treefe4cc46245d3b2d1a42506cab036e27c9c205081 /lib/feature.pm
parent431529dbf3ead68001f1ed06fd4712dec7000e8f (diff)
downloadperl-b42943c4698d2a49df050632f1dff2cff372ed52.tar.gz
Factorise croak() calls and error messages in feature.pm
(suggested by Michael G Schwern) p4raw-id: //depot/perl@29815
Diffstat (limited to 'lib/feature.pm')
-rw-r--r--lib/feature.pm39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/feature.pm b/lib/feature.pm
index 238820e723..4a828d2689 100644
--- a/lib/feature.pm
+++ b/lib/feature.pm
@@ -105,27 +105,19 @@ to C<use feature qw(switch ~~ say err state)>.
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;