Skip to content

Commit

Permalink
Added IO::Stat, and a .stat method for IO
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
Tadeusz Sośnierz authored and moritz committed Jul 28, 2010
1 parent 7e8134c commit 3fbd628
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -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 \
Expand Down
9 changes: 5 additions & 4 deletions src/core/IO.pm
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
49 changes: 49 additions & 0 deletions 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

0 comments on commit 3fbd628

Please sign in to comment.