Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Introduce/use new OBJECTIFTY-PATH helper sub
  • Loading branch information
lizmat committed Feb 7, 2015
1 parent c12c52b commit 3b2c900
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
25 changes: 16 additions & 9 deletions src/core/IO.pm
@@ -1,6 +1,8 @@
my class Instant { ... }
my class IO::Dir { ... }
my class IO::File { ... }
my class Instant { ... }
my class IO::File { ... }
my class IO::Dir { ... }
my class IO::Symlink { ... }
my class IO::Local { ... }

my role IO {
method umask { state $ = :8( qx/umask/.chomp ) }
Expand Down Expand Up @@ -440,22 +442,27 @@ sub FILETEST-READLINK(Str $abspath) {
);
}

sub OBJECTIFY-ABSPATH(Str $abspath, |c) {
FILETEST-f($abspath)
?? IO::File.new(:$abspath, |c)
!! FILETEST-d($abspath)
?? IO::Dir.new(:abspath($abspath ~ '/'), |c)
!! FILETEST-l($abspath)
?? IO::Symlink.new(:$abspath, |c)
!! IO::Local.new(:$abspath, |c);
}
sub DIR-GATHER(Str $abspath,Mu $test) {
gather {
for MAKE-DIR-LIST($abspath,$test) -> $elem {
take FILETEST-d($elem)
?? IO::Dir.new(:abspath($elem ~ '/'))
!! IO::File.new(:abspath($elem));
take OBJECTIFY-ABSPATH($elem);
}
}
}

sub DIR-GATHER-STR(Str $abspath,Mu $test) {
gather {
for MAKE-DIR-LIST($abspath,$test) -> $elem {
take FILETEST-d($elem)
?? $elem ~ '/'
!! $elem;
take FILETEST-d($elem) ?? $elem ~ '/' !! $elem;
}
}
}
Expand Down
16 changes: 3 additions & 13 deletions src/core/IOU.pm
Expand Up @@ -80,19 +80,9 @@ my class IOU does IO::Pathy {
}

method !what(IOU: $abspath, |c) {

if FILETEST-e($abspath) {
if FILETEST-f($abspath) {
return IO::File.new(:$abspath, |c);
}
elsif FILETEST-d($abspath) {
return IO::Dir.new(:$abspath, |c);
}
else {
return IO::Local.new(:$abspath, |c);
}
}
Mu;
FILETEST-e($abspath)
?? OBJECTIFY-ABSPATH($abspath, |c)
!! Mu;
}
}

Expand Down

0 comments on commit 3b2c900

Please sign in to comment.