/usr/share/perl5/utf8/all.pm is in libutf8-all-perl 0.015-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | package utf8::all;
use strict;
use warnings;
use 5.010; # state
# ABSTRACT: turn on Unicode - all of it
our $VERSION = '0.015'; # VERSION
use Import::Into;
use parent qw(Encode charnames utf8 open warnings feature);
use Symbol qw(qualify_to_ref);
# Holds the pointers to the original version of redefined functions
state %_orig_functions;
my @KNOWN_OPTIONS = qw( File::Find Cwd ); # :all is a "tag"
sub import {
my %options = map { $_ => 1 } @_[1 .. $#_]; # First entry in @_ is __PACKAGE__
if (delete $options{':all'}) {
$options{$_} = 1 for @KNOWN_OPTIONS;
}
# only keep known opts
foreach my $opt (keys %options) {
delete $options{$opt}
unless grep { $opt eq $_ } @KNOWN_OPTIONS
}
# Enable features/pragmas in calling package
my $target = caller;
'utf8'->import::into($target);
'open'->import::into($target, qw{:encoding(UTF-8) :std});
'charnames'->import::into($target, qw{:full :short});
'warnings'->import::into($target, qw{FATAL utf8});
'feature'->import::into($target, qw{unicode_strings}) if $^V >= v5.11.0;
'feature'->import::into($target, qw{unicode_eval fc}) if $^V >= v5.16.0;
unless ($^O eq 'Win32') {
no strict qw(refs); ## no critic (TestingAndDebugging::ProhibitNoStrict)
no warnings qw(redefine);
# Replace readdir with utf8 aware version
*{$target . '::readdir'} = \&_utf8_readdir;
$^H{'utf8::all::readdir'} = 1; # Track whether to encode/decode in the redefined function
# Replace glob with utf8 aware version
*{$target . '::glob'} = \&_utf8_glob;
$^H{'utf8::all::glob'} = 1;
# List of redefined non-core functions
my @redefined;
if ($options{'Cwd'}) {
require Cwd;
push @redefined, map "Cwd::$_" => qw(
cwd fastcwd getcwd fastgetcwd
abs_path realpath fast_abs_path
);
}
if ($options{'File::Find'}) {
require File::Find;
push @redefined, map "File::Find::$_" => qw(find finddepth);
}
for my $f (@redefined) {
$^H{"utf8::all::$f"} = 1;
# If we already have the _orig_function, we have redefined the function
# in an earlier load of the module, so we need not do it again
unless ($_orig_functions{$f}) {
$_orig_functions{$f} = \&{$f};
if ($f =~ /^File::Find::(find|finddepth)$/) {
*{$f} = \&{"_utf8_$1"};
} else {
*{$f} = sub { return _utf8_simple_func($f, @_); };
}
}
}
}
# Make @ARGV utf-8 when called from the main package
state $have_encoded_argv = 0;
if ($target eq 'main' && !$have_encoded_argv++) {
$_ = Encode::decode('UTF-8' ,$_) for @ARGV;
}
$^H{'utf8::all'} = 1;
return;
}
sub _utf8_simple_func {
my $func = shift;
my $hints = (caller 1)[10]; # Use caller level 1 because of the added anonymous sub around call
if (not $hints->{"utf8::all::$func"}) {
return $_orig_functions{$func}->(@_);
}
elsif (wantarray) {
return map { Encode::decode('UTF-8' ,$_) }
$_orig_functions{$func}->( map { Encode::encode('UTF-8', $_) } @_ );
}
else {
return Encode::decode('UTF-8',
$_orig_functions{$func}->(map { Encode::encode('UTF-8', $_) } @_)
);
}
}
sub _utf8_readdir(*) { ## no critic (Subroutines::ProhibitSubroutinePrototypes)
my $pre_handle = shift;
my $handle = ref($pre_handle) ? $pre_handle : qualify_to_ref($pre_handle, caller);
my $hints = (caller 0)[10];
if (not $hints->{'utf8::all::readdir'}) {
return CORE::readdir($handle);
} elsif (wantarray) {
return map { Encode::decode('UTF-8' ,$_) } CORE::readdir($handle);
} else {
return Encode::decode('UTF-8', CORE::readdir($handle));
}
}
sub _utf8_glob {
my $arg = $_[0]; # Making this a lexical somehow is important!
my $hints = (caller 0)[10];
if (not $hints->{'utf8::all::glob'}) {
return CORE::glob($arg);
} else {
$arg = Encode::encode('UTF-8', $arg);
if (wantarray) {
return map { Encode::decode('UTF-8' ,$_) } CORE::glob($arg);
} else {
return Encode::decode('UTF-8', CORE::glob($arg));
}
}
}
sub _utf8_find {
my $ref = shift; # This can be the wanted function or a find options hash
# Make argument always into the find's options hash
my %find_options_hash = ref($ref) eq "HASH" ? %$ref : (wanted => $ref);
my $wanted = $find_options_hash{wanted}; # The original wanted function
# Get the hint from the caller (one level deeper if called from _utf8_finddepth)
my $hints = ((caller 1)[3]//"") ne 'utf8::all::_utf8_finddepth' ? (caller 0)[10] : (caller 1)[10];
if (not $hints->{'utf8::all::File::Find::find'}) {
return $_orig_functions{"File::Find::find"}->(\%find_options_hash, @_);
} else {
$find_options_hash{wanted} = sub {
# Decode the file variables
local $_ = Encode::decode('UTF-8', $_);
local $File::Find::name = Encode::decode('UTF-8', $File::Find::name);
local $File::Find::dir = Encode::decode('UTF-8', $File::Find::dir);
local $File::Find::fullname = Encode::decode('UTF-8', $File::Find::fullname);
local $File::Find::topdir = Encode::decode('UTF-8', $File::Find::topdir);
local $File::Find::topdev = Encode::decode('UTF-8', $File::Find::topdev);
local $File::Find::topino = Encode::decode('UTF-8', $File::Find::topino);
local $File::Find::topmode = Encode::decode('UTF-8', $File::Find::topmode);
local $File::Find::topnlink = Encode::decode('UTF-8', $File::Find::topnlink);
$wanted->();
};
return $_orig_functions{"File::Find::find"}->(\%find_options_hash, map { Encode::encode('UTF-8', $_) } @_);
}
}
sub _utf8_finddepth {
my $ref = shift; # This can be the wanted function or a find options hash
return _utf8_find( { bydepth => 1, ref($ref) eq "HASH" ? %$ref : (wanted => $ref) }, @_);
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
utf8::all - turn on Unicode - all of it
=head1 VERSION
version 0.015
=head1 SYNOPSIS
use utf8::all; # Turn on UTF-8, all of it.
# Also provide UTF-8 versions of functions from...
use utf8::all qw(File::Find); # File::Find
use utf8::all qw(Cwd); # Cwd
use utf8::all qw(:all); # everything
open my $in, '<', 'contains-utf8'; # UTF-8 already turned on here
print length 'føø bār'; # 7 UTF-8 characters
my $utf8_arg = shift @ARGV; # @ARGV is UTF-8 too (only for main)
=head1 DESCRIPTION
L<utf8> allows you to write your Perl encoded in UTF-8. That means
UTF-8 strings, variable names, and regular expressions.
C<utf8::all> goes further:
=over 4
=item *
Makes C<@ARGV> encoded in UTF-8 (when C<utf8::all> is used from the main package).
=item *
Filehandles are opened with UTF-8 encoding turned on by default
(including STDIN, STDOUT, STDERR). If you I<don't> want UTF-8 for a
particular filehandle, you'll have to set C<binmode $filehandle>.
=item *
L<charnames> are imported so C<\N{...}> sequences can be used to compile
Unicode characters based on names.
=item *
readdir now returns UTF-8
=item *
L<glob|perlfunc/glob> and the C<< <> >> operator
=back
=head1 Import options
If you provide the C<File::Find> or C<Cwd> options to the
C<use utf8::all> line, those modules are loaded if they haven't
been already, but you will get UTF-8-ified versions instead of the
normal ones. This effect is lexical.
=over 4
=item L<File::Find>
C<find> and C<finddepth>
=item L<Cwd>
C<cwd>, C<fastcwd>, C<getcwd>, C<fastgetcwd>
C<abs_path>, C<realpath>, C<fast_abs_path>
=back
Use C<use utf8::all qw(:all)> to get all of these, plus whatever
we dream up in the future.
=head2 Lexical scope
The pragma is lexically-scoped, so you can do the following if you had
some reason to:
{
use utf8::all;
open my $out, '>', 'outfile';
my $utf8_str = 'føø bār';
print length $utf8_str, "\n"; # 7
print $out $utf8_str; # out as utf8
}
open my $in, '<', 'outfile'; # in as raw
my $text = do { local $/; <$in>};
print length $text, "\n"; # 10, not 7!
=head1 INTERACTION WITH AUTODIE
If you use L<autodie>, which is a great idea, you need to use at least version
B<2.12>, released on L<June 26, 2012|https://metacpan.org/source/PJF/autodie-2.12/Changes#L3>.
Otherwise, autodie obliterates the IO layers set by the L<open> pragma. See
L<RT #54777|https://rt.cpan.org/Ticket/Display.html?id=54777> and
L<GH #7|https://github.com/doherty/utf8-all/issues/7>.
=head1 AVAILABILITY
The project homepage is L<http://metacpan.org/release/utf8-all/>.
The latest version of this module is available from the Comprehensive Perl
Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
site near you, or see L<https://metacpan.org/module/utf8::all/>.
=head1 SOURCE
The development version is on github at L<http://github.com/doherty/utf8-all>
and may be cloned from L<git://github.com/doherty/utf8-all.git>
=head1 BUGS AND LIMITATIONS
You can make new bug reports, and view existing ones, through the
web interface at L<https://github.com/doherty/utf8-all/issues>.
=head1 AUTHORS
=over 4
=item *
Michael Schwern <mschwern@cpan.org>
=item *
Mike Doherty <doherty@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2009 by Michael Schwern <mschwern@cpan.org>.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|