Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

34 lines (29 sloc) 0.948 kb
use v6;
role ABC::Duration {
has $.ticks;
multi sub duration-from-parse($top) is export { #OK
ABC::Duration.new(:ticks(($top ?? +~$top !! 1).Int));
}
multi sub duration-from-parse($top, $bottom) is export { #OK
# $*ERR.say: :$top.perl;
# $*ERR.say: :$bottom.perl;
ABC::Duration.new(:ticks(($top ?? +~$top !! 1).Int / ($bottom ?? +~$bottom !! 2).Int));
}
method duration-to-str() {
given $.ticks {
when 1 { ""; }
when 1/2 { "/"; }
when Int { .Str; }
when Rat {
if $_.denominator == 1 {
~$_.numerator;
} elsif $_.numerator == 1 {
"/" ~ $_.denominator;
} else {
$_.numerator ~ "/" ~ $_.denominator;
}
}
die "Duration must be Int or Rat, but it's { .WHAT }";
}
}
}
Jump to Line
Something went wrong with that request. Please try again.