Permalink
Browse files

[App::Pls] implemented 'fetch'

All t/subcommands/fetch.t tests now pass.
  • Loading branch information...
1 parent 22f24b5 commit 44c586b6807480d27e90cd5b138fd8f1aeb60339 @masak committed Jun 13, 2010
Showing with 58 additions and 4 deletions.
  1. +55 −4 lib/App/Pls.pm
  2. +3 −0 t/subcommands/fetch.t
View
@@ -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 {
@@ -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) {
View
@@ -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(

0 comments on commit 44c586b

Please sign in to comment.