Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: adc11251ae
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 72 lines (59 sloc) 1.7 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
class Ecosystem;

has $projects-dir; # no twigil because ?
has %!project-info;

method new(:$projects-dir!) {
    self.bless(
        self.CREATE(),
        projects-dir => $projects-dir,
        project-info => load-project-list('projects.list'),
    );
}

method contains-project($project) {
    # RAKUDO: :exists [perl #59794]
    return %!project-info.exists($project);
}

method get-info-on($project) {
    return %!project-info{$project};
}

method regular-projects() {
    return %!project-info.keys.grep:
        { !%!project-info{$_}.exists('type')
          || !(%!project-info{$_}<type> eq 'pseudo'|'bootstrap') };
}

method installed-projects() {
    return self.regular-projects.grep: { "$projects-dir/$_" ~~ :d };
}

method uninstalled-projects() {
    return self.regular-projects.grep: { "$projects-dir/$_" !~~ :d };
}

method is-installed( Str $project ) {
    return "$projects-dir/$project" ~~ :d;
}

sub load-project-list(Str $filename) {
    my $fh = open($filename)
        or die "Can't open '$filename': $!";

    my %overall;
    my $current-name;
    my %current;
    for $fh.lines {
        when / ^ \s* ['#' | $ ] / { next };
        when / ^ (\S+) \: \s* ['#' | $ ] / {
            if $current-name.defined {
                %overall{$current-name} = %current.clone;
            }
            %current = ();
            $current-name = ~$0;
        }
        when / ^ \s+ (\S+) ':' \s* (\S+) \s* ['#' | $ ] / {
            %current{~$0} = ~$1;
        }
        default {
            warn "don't know how to parse the line «$_», ignoring it"
        }
    }
    if %current {
        %overall{$current-name} = %current;
    }

    return %overall;
}

# vim: ft=perl6
Something went wrong with that request. Please try again.