Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
flesh out Version a bit
* fixed constructor to properly handle :plus * .Str now properly handles * wildcards and trailing + * first shot at ACCEPTS
- Loading branch information
Showing
1 changed file
with
17 additions
and
4 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 |
|---|---|---|
| @@ -1,16 +1,29 @@ | ||
| class Version is List { | ||
| has Bool $.plus = False; | ||
| method new(*@positional, :$plus) { | ||
| my $new := nextwith(@positional); | ||
| nqp::bindattr($new, Version, '$!plus', so $plus); | ||
| $new; | ||
| self.List::new(@positional).MYBUILD(?$plus); | ||
| } | ||
| submethod MYBUILD(Bool $plus) { | ||
| $!plus = $plus; | ||
| self; | ||
| } | ||
| multi method Str(Version:D:) { | ||
| 'v' ~ self.join('.'); | ||
| 'v' ~ self.map({ $_ ~~ Whatever ?? '*' !! $_}).join('.') ~ ($!plus ?? '+' !! ''); | ||
| } | ||
| multi method gist(Version:D:) { self.Str } | ||
| multi method perl(Version:D:) { | ||
| self.^name ~ '.new(' ~ self.List::perl ~ ', :plus(' ~ $!plus.perl ~ '))'; | ||
|
|
||
| } | ||
| multi method ACCEPTS(Version:D: Version:D $other) { | ||
| for self.kv -> $i, $v { | ||
| next if $v ~~ Whatever; | ||
| my $o = $other[$i]; | ||
| return True unless defined $o; | ||
| next if $o ~~ Whatever; | ||
| return $.plus if $o after $v; | ||
| return False if $o before $v; | ||
| } | ||
| True; | ||
| } | ||
| } |