aboutsummaryrefslogtreecommitdiff
path: root/lib/App/MediaControl/FS.rakumod
blob: b8f68d2c53986b70fcb8186c35b858228423ad65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use v6.d;
 
class App::MediaControl::FS {
    has IO::Path() $.root is required;
    has $!extensions;
 
    submethod TWEAK(:$extensions{
        $!extensions = any($extensions.Slip);
    }
 
    method get-children-of(Str $path) {
        my $base = $!root.child($path);
        return @() unless $base.d;
        
        my @children = eager $base.dir(
            test => -> $f {
                my $based-f = $base.child($f);
 
 
                $based-f.d ?? $f ~~ $*SPEC.curupdir !!
                ($based-f.extension ~~ $!extensions?? True !!
                False;
            },
        );
 
        return @children.map(
            -> $f {
                %name => $f.basenameis_dir => $f.d );
            }
        ).sort({ .<name> });
    }
 
    method exists(Str $path) {
        return $!root.child($path).e;
    }
}