22
33unit module Terminal::Widgets::Volatile::DirTree ;
44
5+ use Terminal::Widgets::Volatile::Tree;
56
6- role Node {
7- has IO ::Path: D () $ . path is required ;
8- has Node $ . parent ;
7+ constant Tree = Terminal::Widgets::Volatile::Tree;
98
109
11- # | Simplified gist that does not traverse parents
12- method gist (::? CLASS: D : ) {
13- my $ short-name = self .^ name . subst (' Terminal::Widgets::Volatile::' , ' ' );
14- $ short-name ~ ' :' ~ $ ! path . path
15- }
10+ role PathContainer {
11+ has IO ::Path: D () $ . path is required ;
1612
17- # | Find root node via parent chain, runtime is O(depth)
18- method root (::? CLASS: D : ) {
19- my $ root = self ;
20- $ root .= parent while $ root . parent ;
21- $ root
13+ # | Simplified gist that does not traverse parents, and includes path
14+ method gist (::? CLASS: D : ) {
15+ self . gist-name ~ ' :' ~ $ ! path . path
2216 }
2317}
2418
25- class Dev does Node {
26- }
19+ role Node does Tree::Node does PathContainer { }
20+ role Leaf does Tree::Leaf does PathContainer { }
21+ role Parent does Tree::Parent does PathContainer { }
2722
28- class File does Node {
29- }
23+ class Misc does Node { }
24+ class File does Leaf { }
25+ class Dev does Node { }
3026
3127class SymLink does Node {
3228 has IO ::Path: D () $ . target is required ;
@@ -38,9 +34,9 @@ class SymLink does Node {
3834 }
3935}
4036
41- class Dir does Node {
42- has Node: D @ ! children is built;
43- has Instant : D $ . cache-time .= from-posix-nanos(0 );
37+ class Dir does Parent {
38+ has Tree:: Node: D @ ! children is built;
39+ has Instant : D $ . cache-time .= from-posix-nanos(0 );
4440
4541
4642 # | Lazily find (and cache) children, forcing a refresh if requested
@@ -57,12 +53,9 @@ class Dir does Node {
5753 . l ?? SymLink. new (parent => self , path => $ _ , target => . readlink) !!
5854 . f ?? File. new ( parent => self , path => $ _ ) !!
5955 . dev ?? Dev. new ( parent => self , path => $ _ ) !!
60- Node . new ( parent => self , path => $ _ ) ;
56+ Misc . new ( parent => self , path => $ _ ) ;
6157 };
6258 }
6359 @ ! children
6460 }
6561}
66-
67- class Root is Dir {
68- }
0 commit comments