Skip to content

Commit

Permalink
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
moritz committed May 13, 2012
1 parent f685cb6 commit f5288fc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/core/Version.pm
@@ -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;
}
}

0 comments on commit f5288fc

Please sign in to comment.