basic porting work for SCSite
[scpubgit/App-SCS.git] / lib / App / SCS.pm
index 56b393b..ca1d791 100644 (file)
@@ -62,8 +62,9 @@ sub _build_web {
 sub BUILD {
   my ($self) = @_;
   $self->load_plugin(Core => {});
-  foreach my $spec (@{$self->config->{plugins}||[]}) {
-    $self->load_plugin(@$spec);
+  my @plist = @{$self->config->{plugins}||[]};
+  while (my ($name, $conf) = splice @plist, 0, 2) {
+    $self->load_plugin($name, $conf);
   }
 }
 
@@ -79,4 +80,27 @@ sub load_plugin {
   return;
 }
 
+sub run_if_script {
+  my $self = shift;
+  if (caller(1)) {
+    return 1;
+  } else {
+    return $self->run;
+  }
+}
+
+sub run {
+  my $self = shift;
+  my $env = {
+    argv => \@ARGV,
+    stdin => \*STDIN,
+    stdout => \*STDOUT,
+    stderr => \*STDERR,
+  };
+  foreach my $p (@{$self->plugins}) {
+    return if $p->run_cli($env);
+  }
+  $self->web->run;
+}
+
 1;