Skip to content

Commit c17d196

Browse files
committed
Search::Dict: clean up code
- Remove 'require 5.000'. In theory, this would give a nice runtime error message when run under perl4; in practice, this file doesn't even parse as perl4 due to 'use strict', 'our', and '->' method calls. - Use numeric comparison with $], not string comparison. (In practice, this would probably only start failing once we reach perl 10, but still.) - Don't repeatedly check $fc_available at runtime. Just define a fallback fc() in terms of lc() if CORE::fc is not available. - Add missing $key argument to sample code in SYNOPSIS. This fixes <https://rt.cpan.org/Ticket/Display.html?id=97189>.
1 parent 68944d4 commit c17d196

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

dist/Search-Dict/lib/Search/Dict.pm

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package Search::Dict;
2-
require 5.000;
3-
require Exporter;
2+
use strict;
3+
use Exporter;
44

5-
my $fc_available;
65
BEGIN {
7-
$fc_available = '5.015008';
8-
if ( $] ge $fc_available ) {
9-
require feature;
10-
'feature'->import('fc'); # string avoids warning on old Perls <sigh>
11-
}
6+
if ("$]" >= 5.015008) {
7+
require feature;
8+
'feature'->import('fc'); # string avoids warning on old Perls <sigh>
9+
} else {
10+
# ($) prototype, not (_), for perl 5.8 compatibility, just in case
11+
*fc = sub ($) { lc $_[0] };
12+
}
1213
}
1314

14-
use strict;
15-
16-
our $VERSION = '1.07';
15+
our $VERSION = '1.08';
1716
our @ISA = qw(Exporter);
1817
our @EXPORT = qw(look);
1918

@@ -27,7 +26,7 @@ Search::Dict - look - search for key in dictionary file
2726
look *FILEHANDLE, $key, $dict, $fold;
2827
2928
use Search::Dict;
30-
look *FILEHANDLE, $params;
29+
look *FILEHANDLE, $key, $params;
3130
3231
=head1 DESCRIPTION
3332
@@ -80,7 +79,7 @@ sub look {
8079
$blksize ||= 8192;
8180
$key =~ s/[^\w\s]//g if $dict;
8281
if ( $fold ) {
83-
$key = $] ge $fc_available ? fc($key) : lc($key);
82+
$key = fc($key);
8483
}
8584
# find the right block
8685
my($min, $max) = (0, int($size / $blksize));
@@ -95,7 +94,7 @@ sub look {
9594
chomp;
9695
s/[^\w\s]//g if $dict;
9796
if ( $fold ) {
98-
$_ = $] ge $fc_available ? fc($_) : lc($_);
97+
$_ = fc($_);
9998
}
10099
if (defined($_) && $comp->($_, $key) < 0) {
101100
$min = $mid;
@@ -117,7 +116,7 @@ sub look {
117116
chomp;
118117
s/[^\w\s]//g if $dict;
119118
if ( $fold ) {
120-
$_ = $] ge $fc_available ? fc($_) : lc($_);
119+
$_ = fc($_);
121120
}
122121
last if $comp->($_, $key) >= 0;
123122
}

0 commit comments

Comments
 (0)