Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 34 lines (29 sloc) 0.948 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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 }";
        }
    }
}
Something went wrong with that request. Please try again.