Skip to content

Commit e06ae46

Browse files
committed
File::stat: default to $_ if called without arguments
1 parent 54ba806 commit e06ae46

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

lib/File/stat.pm

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ sub populate {
194194
return $stob;
195195
}
196196

197-
sub lstat :prototype($) { populate(CORE::lstat(shift)) }
197+
sub lstat :prototype(_) { populate(CORE::lstat(shift)) }
198198

199-
sub stat :prototype($) {
199+
sub stat :prototype(_) {
200200
my $arg = shift;
201201
my $st = populate(CORE::stat $arg);
202202
return $st if defined $st || ref $arg;
@@ -293,17 +293,19 @@ function functions with their full qualified names.
293293
On the other hand, the built-ins are still available
294294
via the C<CORE::> pseudo-package.
295295
296-
=head1 BUGS
296+
As of version 1.15 (provided with perl 5.44) C<stat> and C<lstat> can be
297+
called without arguments, in which case C<$_> is used (just like the
298+
built-in C<stat>/C<lstat> functions):
297299
298-
As of Perl 5.8.0 after using this module you cannot use the implicit
299-
C<$_> or the special filehandle C<_> with stat() or lstat(), trying
300-
to do so leads into strange errors. The workaround is for C<$_> to
301-
be explicit
300+
my $st_1 = stat; # stat($_)
301+
my $st_2 = lstat; # lstat($_)
302302
303-
my $stat_obj = stat $_;
303+
=head1 BUGS
304304
305-
and for C<_> to explicitly populate the object using the unexported
306-
and undocumented populate() function with CORE::stat():
305+
As of Perl 5.8.0 after using this module you cannot use the special
306+
filehandle C<_> with stat() or lstat(); trying to do so leads to strange
307+
errors. The workaround is to explicitly populate the object using the
308+
unexported and undocumented populate() function with CORE::stat():
307309
308310
my $stat_obj = File::stat::populate(CORE::stat(_));
309311

lib/File/stat.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ SKIP:
237237
isa_ok $ret[0], 'File::stat', 'successful stat in list context';
238238
}
239239

240+
{
241+
# implicit $_
242+
$_ = $file;
243+
isa_ok stat, 'File::stat', 'stat()';
244+
}
245+
240246
# Testing pretty much anything else is unportable.
241247

242248
done_testing;

0 commit comments

Comments
 (0)