Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- takes a volume, dirname and basename into a single object - should replace List of Pairs approach used by IO::Spec::X.split - completely compatible with List of Pairs interface for now Did not use the improved interface in IO::Path yet. Since this commit is spectest clean, it proves that the List of Pairs interface is working. Any ecosystem module out there should also have the benefit of this interface, which should probably need to have an official deprecation cycle.
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class IO::Path::Parts | ||
does Positional # all of these can go as soon as we don't need the compat | ||
does Iterable # with the original "List of Pairs" implemention anymore. | ||
{ | ||
has str $.volume; | ||
has str $.dirname; | ||
has str $.basename; | ||
|
||
method !SET-SELF($!volume, $!dirname, $!basename) { self } | ||
method new(\volume, \dirname, \basename) { | ||
nqp::create(self)!SET-SELF(volume, dirname, basename) | ||
} | ||
|
||
method raku() { | ||
'IO::Path::Parts.new(' | ||
~ $!volume.raku | ||
~ ',' | ||
~ $!dirname.raku | ||
~ ',' | ||
~ $!basename.raku | ||
~ ')' | ||
} | ||
|
||
#------------------------------------------------------------------------------- | ||
# all of the code below is just to provide a compatibility layer with the | ||
# original List of Pairs / Map implementation. As soon as this is no longer | ||
# needed, this can go. | ||
|
||
method by-index(int $pos) is implementation-detail { | ||
$pos == 2 | ||
?? :$!basename | ||
!! $pos == 1 | ||
?? :$!dirname | ||
!! $pos | ||
?? Nil | ||
!! :$!volume | ||
} | ||
|
||
class Iterate does Iterator { | ||
has $!parts; | ||
has int $!i; | ||
method new(\parts) { | ||
nqp::p6bindattrinvres(nqp::create(self),self,'$!parts',parts) | ||
} | ||
method pull-one() { $!i < 3 ?? $!parts.by-index($!i++) !! IterationEnd } | ||
} | ||
method iterator() { Iterate.new(self) } | ||
|
||
method AT-POS(int $pos) { self.by-index($pos) } | ||
} | ||
|
||
# vim: ft=perl6 expandtab sw=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters