← Back to index

lib/BDD/Behave/Version.rakumod

3 / 3 lines covered (100.0%)

1use v6.d;23unit module BDD::Behave::Version;45our sub from-meta-file(IO::Path $path --> Str) {6  return Str unless $path.defined && $path.e;78  my $content = $path.slurp;910  if $content ~~ / '"version"' \s* ':' \s* '"' (<-["]>+) '"' / {11    return ~$0;12  }1314  Str;15}1617our sub from-installed-distribution(--> Str) {18  my $ver;1920  try {21    my $spec = CompUnit::DependencySpecification.new(:short-name<BDD::Behave>);22    my $cu   = $*REPO.need($spec);2324    if $cu.defined && $cu.distribution.defined {25      my $meta-ver = $cu.distribution.meta<version>;26      $ver = $meta-ver.Str if $meta-ver.defined && $meta-ver.Str.chars;27    }2829    CATCH { default { } }30  }3132  $ver // Str;33}3435our sub from-source-checkout(IO::Path $program-path --> Str) {36  return Str unless $program-path.defined;3738  my $dir = $program-path.absolute.IO.parent;3940  while $dir.defined && $dir.absolute ne '/' {41    my $meta = $dir.add('META6.json');42    my $ver  = from-meta-file($meta);4344    return $ver if $ver.defined;4546    $dir = $dir.parent;47  }4849  Str;50}5152our sub version(IO::Path :$program-path = $*PROGRAM --> Str) {53  my $installed = from-installed-distribution();5455  return $installed if $installed.defined;5657  my $source = from-source-checkout($program-path);5859  return $source if $source.defined;6061  'unknown';62}