1
# vi: set ts=4 sw=4 ht=4 et :
11
use perl5i::1::DateTime;
16
use perl5i::1::autobox;
18
use perl5i::VERSION; our $VERSION = perl5i::VERSION->VERSION;
20
our $Latest = perl5i::VERSION->latest;
23
# This works around their lexical nature.
25
use parent 'perl5i::1::autobox';
26
use parent 'autovivification';
30
## no critic (Subroutines::RequireArgUnpacking)
41
# Modern::Perl won't pass this through to our caller.
43
mro::set_mro( $caller, 'c3' );
45
load_in_caller( $caller => (
46
["CLASS"], ["File::chdir"],
47
[English => qw(-no_match_vars)],
48
["Want" => qw(want)], ["Try::Tiny"], ["Perl6::Caller"], ["Carp"]
51
# Have to call both or it won't work.
52
perl5i::1::autobox::import($class);
53
autovivification::unimport($class);
56
open::import($class, ":encoding(utf8)");
57
open::import($class, ":std");
59
# Export our gmtime() and localtime()
60
(\&{$Latest .'::DateTime::dt_gmtime'})->alias($caller, 'gmtime');
61
(\&{$Latest .'::DateTime::dt_localtime'})->alias($caller, 'localtime');
62
(\&{$Latest .'::DateTime::dt_time'})->alias($caller, 'time');
63
(\&stat)->alias( $caller, 'stat' );
64
(\&lstat)->alias( $caller, 'lstat' );
65
(\&utf8_open)->alias($caller, 'open');
67
# fix die so that it always returns 255
68
*CORE::GLOBAL::die = sub {
69
# Leave a single ref be
71
return CORE::die(@_) if @_ == 1 and ref $_[0];
73
my $error = join '', @_;
74
unless ($error =~ /\n$/) {
75
my ($file, $line) = (caller)[1,2];
76
$error .= " at $file line $line.\n";
80
return CORE::die($error);
85
$_ = Encode::decode('utf8', $_) for @ARGV;
90
# autodie needs a bit more convincing
91
@_ = ( $class, ":all" );
92
goto &autodie::import;
95
sub unimport { $^H{perl5i} = 0 }
97
sub utf8_open(*;$@) { ## no critic (Subroutines::ProhibitSubroutinePrototypes)
100
$ret = CORE::open $_[0];
103
$ret = CORE::open $_[0], $_[1], @_[2..$#_];
106
# Don't try to binmode an unopened filehandle
107
return $ret unless $ret;
109
my $h = (caller 1)[10];
110
binmode $_[0], ":encoding(utf8)" if $h->{perl5i};
119
for my $spec (@modules) {
120
my( $module, @args ) = @$spec;
123
## no critic (BuiltinFunctions::ProhibitStringyEval)
126
\$module->import(\@args);
128
} or die "Error while perl5i loaded $module => @args: $@";
135
# File::stat does not play nice in list context
137
return CORE::stat(@_) if wantarray;
138
return File::stat::stat(@_);
142
return CORE::lstat(@_) if wantarray;
143
return File::stat::lstat(@_);