Skip to content

Commit

Permalink
[App::Pls] implemented 'fetch'
Browse files Browse the repository at this point in the history
All t/subcommands/fetch.t tests now pass.
  • Loading branch information
Carl Masak committed Jun 13, 2010
1 parent 22f24b5 commit 44c586b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
59 changes: 55 additions & 4 deletions lib/App/Pls.pm
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
use v6;

enum State <gone fetched built tested installed>;
subset State of Str where {
'gone' | 'fetched' | 'built' | 'tested' | 'installed'
};
enum Result <failure success forced-success>;

role App::Pls::ProjectsState {
method state-of($project --> State) { !!! }
method set-state-of($project, State $state) { !!! }
method deps-of($project) { !!! }
}

class App::Pls::ProjectsState::Hash does App::Pls::ProjectsState {
has %!projects;

method new(%projects is rw) {
self.bless(*, :%projects);
}

method state-of($project --> State) {
(%!projects{$project} // { :state<gone> })<state> // 'gone';
}

method set-state-of($project, State $state) {
%!projects{$project}<state> = $state;
}

method deps-of($project) {
if %!projects.exists($project) {
if %!projects{$project}.exists('deps') {
return %!projects{$project}<deps>.list;
}
return ();
}
die "No such project: $project";
}
}

role App::Pls::Fetcher {
method fetch($project) { !!! }
}

role App::Pls::Builder {
Expand All @@ -27,11 +56,33 @@ class App::Pls::Core {
has App::Pls::Builder $!builder;

method state-of($project) {
return -1;
return $!projects.state-of($project);
}

method fetch(*@projects) {
return;
method fetch(*@projects --> Result) {
for @projects -> $project {
my %*seen-projects;
return failure
if self!fetch-helper($project) == failure;
}
return success;
}

method !fetch-helper($project --> Result) {
%*seen-projects{$project}++;
for $!projects.deps-of($project) -> $dep {
return failure
if %*seen-projects{$dep};
return failure
if self!fetch-helper($dep) == failure;
}
if $!fetcher.fetch($project) == success {
$!projects.set-state-of($project, 'fetched');
return success;
}
else {
return failure;
}
}

method build(*@projects) {
Expand Down
3 changes: 3 additions & 0 deletions t/subcommands/fetch.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ my %projects =
;

class Mock::Fetcher does App::Pls::Fetcher {
method fetch($project --> Result) {
$project eq 'will-fail' ?? failure !! success;
}
}

my $core = App::Pls::Core.new(
Expand Down

0 comments on commit 44c586b

Please sign in to comment.