# New Ticket Created by Tadeusz SoĊnierz # Please include the string: [perl #76772] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=76772 >
Here's a patch adding an interface to Parrot's stat Opcode in Rakudo. I've consulted it with Moritz Lenz who also thought it's a nice feature to have. Now it's possible to get file information like this: 'filename'.IO.stat.size 'filename'.IO.stat.isdir ...etc, etc. Some stat features are not working with the current Rakudo for me (e.g. uid always returns -1, isdev always returns 0) but besides this, which is some Parrot issue, everything works fine and no spectests are failing. Kind Regards, Ted
>From 2c62656e262585066bb5b33c0ad207b77cdcdccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20So=C5=9Bnierz?= <tadzi...@gmail.com> Date: Wed, 28 Jul 2010 15:44:11 +0000 Subject: [PATCH] Added IO::Stat, and a .stat method for IO --- build/Makefile.in | 1 + src/core/IO.pm | 9 +++++---- src/core/IO/Stat.pm | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/core/IO/Stat.pm diff --git a/build/Makefile.in b/build/Makefile.in index e7bc8e2..a53f999 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -214,6 +214,7 @@ CORE_SOURCES = \ src/core/IO/ArgFiles.pm \ src/core/IO/Socket.pm \ src/core/IO/Socket/INET.pm \ + src/core/IO/Stat.pm \ src/core/Parameter.pm \ src/core/Signature.pm \ src/core/Block.pm \ diff --git a/src/core/IO.pm b/src/core/IO.pm index b69751f..ffec985 100644 --- a/src/core/IO.pm +++ b/src/core/IO.pm @@ -4,6 +4,7 @@ class IO is Cool { has $.autoflush is rw; has $.path; + has $.stat = ::IO::Stat.new(path => $.path); multi method close() is export { try { @@ -140,17 +141,17 @@ class IO is Cool { # file test operations multi method d() { - self.e ?? ?pir::stat__ISI($.path, 2) !! Bool; + self.e ?? $.stat.isdir !! Bool; } multi method e() { - ?pir::stat__ISI($.path, 0); + $.stat.exists; } multi method f() { - self.e ?? !pir::stat__ISI($.path, 2) !! Bool; + self.e ?? !$.stat.isdir !! Bool; } multi method s() { - self.e ?? pir::stat__ISI($.path, 1) !! Any; + self.e ?? $.stat.size !! Any; } multi method l() { diff --git a/src/core/IO/Stat.pm b/src/core/IO/Stat.pm new file mode 100644 index 0000000..dba9c86 --- /dev/null +++ b/src/core/IO/Stat.pm @@ -0,0 +1,49 @@ +class IO::Stat { + has $.path; + + method exists { + ?pir::stat__isi($.path, 0); + } + + method size { + pir::stat__isi($.path, 1); + } + + method isdir { + ?pir::stat__isi($.path, 2); + } + + method isdev { + ?pir::stat__isi($.path, 3); + } + + method createtime { + pir::stat__isi($.path, 4); + } + + method accesstime { + pir::stat__isi($.path, 5); + } + + method modifytime { + pir::stat__isi($.path, 6); + } + + method changetime { + pir::stat__isi($.path, 7); + } + + method backuptime { + pir::stat__isi($.path, 8); + } + + method uid { + pir::stat__isi($.path, 9); + } + + method gid { + pir::stat__isi($.path, 10); + } +} + +# vim: ft=perl6 -- 1.7.1.1