t/io/fflush.t See if auto-flush on fork/exec/system/qx works
t/io/fs.t See if directory manipulations work
t/io/inplace.t See if inplace editing works
+t/io/iofile.t See if we can load IO::File on demand
t/io/iprefix.t See if inplace editing works with prefixes
t/io/layers.t See if PerlIO layers work
t/io/nargv.t See if nested ARGV stuff works
/* Right now this is exclusively for the benefit of S_method_common
in pp_hot.c */
if (stash) {
+ /* If we can't find an IO::File method, it might be a call on
+ * a filehandle. If IO:File has not been loaded, try to
+ * require it first instead of croaking */
+ const char *stash_name = HvNAME_get(stash);
+ const char *io_file = "IO/File.pm";
+ if (stash_name && strEQ(stash_name,"IO::File")
+ && ! hv_exists(GvHVn(PL_incgv),io_file, strlen(io_file))
+ ) {
+ require_pv(io_file);
+ gv = gv_fetchmeth(stash, name, nend - name, 0);
+ if (gv)
+ return gv;
+ }
Perl_croak(aTHX_
"Can't locate object method \"%s\" via package \"%.*s\"",
name, (int)HvNAMELEN_get(stash), HvNAME_get(stash));
This is particularly useful to suppresses the default actions of a
C<Devel::*> module's C<import> method whilst still loading it for debugging.
+=head2 Filehandle method calls load IO::File on demand
+
+When a method call on a filehandle would die because the method can not
+be resolved and L<IO::File> has not been loaded, Perl now loads IO::File
+via C<require> and attempts method resolution again:
+
+ open my $fh, ">", $file;
+ $fh->binmode(":raw"); # loads IO::File and succeeds
+
+This also works for globs like STDOUT, STDERR and STDIN:
+
+ STDOUT->autoflush(1);
+
+Because this on-demand load only happens if method resolution fails, the
+legacy approach of manually loading an IO::File parent class for partial
+method support still works as expected:
+
+ use IO::Handle;
+ open my $fh, ">", $file;
+ $fh->autoflush(1); # IO::File not loaded
+
=head1 Security
XXX Any security-related notices go here. In particular, any security
--- /dev/null
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require './test.pl';
+}
+
+$| = 1;
+use warnings;
+use Config;
+
+plan tests => 3;
+
+# this is essentially the same as a test on a lexical filehandle in
+# t/io/open.t, but done in a separate test process against a standard
+# filehandle
+
+# check that we can call methods on filehandles auto-magically
+# and have IO::File loaded for us
+{
+ is( $INC{'IO/File.pm'}, undef, "IO::File not loaded" );
+ ok( eval { STDOUT->autoflush(1); 1 }, 'STDOUT->autoflush(1) lives' );
+ ok( $INC{'IO/File.pm'}, "IO::File now loaded" );
+}
use warnings;
use Config;
-plan tests => 111;
+plan tests => 114;
my $Perl = which_perl();
# when this fails, it leaves an extra file:
or unlink \*STDOUT;
}
+
+# check that we can call methods on filehandles auto-magically
+# and have IO::File loaded for us
+{
+ is( $INC{'IO/File.pm'}, undef, "IO::File not loaded" );
+ my $var = "";
+ open my $fh, ">", \$var;
+ ok( eval { $fh->autoflush(1); 1 }, '$fh->autoflush(1) lives' );
+ ok( $INC{'IO/File.pm'}, "IO::File now loaded" );
+}