Skip to content

Commit

Permalink
0.0.2: return more permissions in shortflag form
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Weidenbaum committed Aug 17, 2016
1 parent 1684e3c commit d0c5cb5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions META.info
@@ -1,8 +1,8 @@
{
"name" : "File::Presence",
"version" : "0.0.1",
"version" : "0.0.2",
"author" : "Andy Weidenbaum",
"description" : "Check that a file / directory exists and is readable",
"description" : "Check permissions of potentially nonexistent files",
"license" : "http://unlicense.org/UNLICENSE",
"source-type" : "git",
"source-url" : "git://github.com/atweiden/file-presence.git",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -19,8 +19,8 @@ say exists-readable-file($config-file)
?? 'readable file exists'
!! 'readable file dne';

say File::Presence.show($config-dir); # { :exists, :readable, :!file, :dir }
say File::Presence.show($config-file); # { :exists, :readable, :file, :!dir }
say File::Presence.show($config-dir); # { :e, :d, :!f, :r, :w, :x }
say File::Presence.show($config-file); # { :e, :!d, :f, :r, :w, :!x }
```


Expand Down
14 changes: 9 additions & 5 deletions lib/File/Presence.pm
@@ -1,37 +1,41 @@
use v6;
unit class File::Presence;

constant $VERSION = v0.0.1;
constant $VERSION = v0.0.2;

subset PresenceHash of Hash where { .keys.sort ~~ <dir exists file readable> }
subset PresenceHash of Hash where { .keys.sort ~~ <d e f r w x> }

method show(Str $file) returns PresenceHash
{
my Bool $e = $file.IO.e;
my Bool $d = False;
my Bool $f = False;
my Bool $r = False;
my Bool $w = False;
my Bool $x = False;

if $e
{
$d = $file.IO.d;
$f = $file.IO.f;
$r = $file.IO.r;
$w = $file.IO.w;
$x = $file.IO.x;
}

my PresenceHash $p = %(:dir($d), :exists($e), :file($f), :readable($r));
my PresenceHash $p = %(:$d, :$e, :$f, :$r, :$w, :$x);
}

sub exists-readable-dir(Str $dir) is export returns Bool
{
my PresenceHash $p = File::Presence.show($dir);
$p<exists> && $p<readable> && $p<dir>;
$p<e> && $p<r> && $p<d>;
}

sub exists-readable-file(Str $file) is export returns Bool
{
my PresenceHash $p = File::Presence.show($file);
$p<exists> && $p<readable> && $p<file>;
$p<e> && $p<r> && $p<f>;
}

# vim: ft=perl6 fdm=marker fdl=0
6 changes: 3 additions & 3 deletions t/methods/show.t
Expand Up @@ -9,9 +9,9 @@ subtest
{
my Str $dir = 't/methods';
my Str $file = 't/methods/show.t';
is-deeply File::Presence.show($dir), { :exists, :readable, :!file, :dir };
is-deeply File::Presence.show($file), { :exists, :readable, :file, :!dir };
is-deeply File::Presence.show('bzzt'), { :!exists, :!readable, :!file, :!dir };
is-deeply File::Presence.show($dir), { :e, :d, :!f, :r, :w, :x };
is-deeply File::Presence.show($file), { :e, :!d, :f, :r, :w, :!x }
is-deeply File::Presence.show('bzzt'), { :!e, :!d, :!f, :!r, :!w, :!x };
}

# vim: ft=perl6 fdm=marker fdl=0

0 comments on commit d0c5cb5

Please sign in to comment.