[Bps-public-commit] SD branch, master, updated. 61ea767128fea0ef8f1281f1db1b75ef62011b3b

spang at bestpractical.com spang at bestpractical.com
Sat Aug 15 09:44:00 EDT 2009


The branch, master has been updated
       via  61ea767128fea0ef8f1281f1db1b75ef62011b3b (commit)
       via  2196603acae32970dcf47603afb0bd6630343fd0 (commit)
       via  16b8aabec64ff51006e82beadb6f7bbd524d8e61 (commit)
      from  eba358f0532a8136677306decaf6c51e2c446a21 (commit)

Summary of changes:
 lib/App/SD/CLI/Command/Browser.pm |   32 ++++++++++++++++++++------------
 lib/App/SD/CLI/Command/Server.pm  |    8 +++-----
 2 files changed, 23 insertions(+), 17 deletions(-)

- Log -----------------------------------------------------------------
commit 16b8aabec64ff51006e82beadb6f7bbd524d8e61
Author: Christine Spang <spang at bestpractical.com>
Date:   Sat Aug 15 13:54:44 2009 +0100

    Check x-www-browser first, and move www-browser much further down in the list of browsers to try.

diff --git a/lib/App/SD/CLI/Command/Browser.pm b/lib/App/SD/CLI/Command/Browser.pm
index 1deaaf7..4b6ab06 100644
--- a/lib/App/SD/CLI/Command/Browser.pm
+++ b/lib/App/SD/CLI/Command/Browser.pm
@@ -37,9 +37,9 @@ sub open_url_cmd {
         return 'start';
     }
 
-    for my $cmd (qw|www-browser htmlview
-                    gnome-open gnome-moz-remote 
-                    firefox iceweasel opera w3m lynx|) {
+    for my $cmd (qw|x-www-browser htmlview
+                    gnome-open gnome-moz-remote
+                    firefox iceweasel opera www-browser w3m lynx|) {
         my $cmd_path = `which $cmd`;
         chomp($cmd_path);
         if ( $cmd_path &&  -f $cmd_path && -x _ ) {

commit 2196603acae32970dcf47603afb0bd6630343fd0
Author: Christine Spang <spang at bestpractical.com>
Date:   Sat Aug 15 13:58:31 2009 +0100

    Browser command should inherit from SD's Server command, not Prophet's.

diff --git a/lib/App/SD/CLI/Command/Browser.pm b/lib/App/SD/CLI/Command/Browser.pm
index 4b6ab06..467efa6 100644
--- a/lib/App/SD/CLI/Command/Browser.pm
+++ b/lib/App/SD/CLI/Command/Browser.pm
@@ -1,7 +1,7 @@
 package App::SD::CLI::Command::Browser;
 use Any::Moose;
 
-extends 'Prophet::CLI::Command::Server';
+extends 'App::SD::CLI::Command::Server';
 
 sub setup_server {
     my $self = shift;

commit 61ea767128fea0ef8f1281f1db1b75ef62011b3b
Author: Christine Spang <spang at bestpractical.com>
Date:   Sat Aug 15 14:21:15 2009 +0100

    Refactor to share more code, make forking code clearer.
    
    Calling Prophet::CLI->end_pager() also seems to cure the "browser
    opens up before server has been started" bug in most cases,
    for some awesome subtle reason.

diff --git a/lib/App/SD/CLI/Command/Browser.pm b/lib/App/SD/CLI/Command/Browser.pm
index 467efa6..53f63e3 100644
--- a/lib/App/SD/CLI/Command/Browser.pm
+++ b/lib/App/SD/CLI/Command/Browser.pm
@@ -3,12 +3,15 @@ use Any::Moose;
 
 extends 'App::SD::CLI::Command::Server';
 
-sub setup_server {
+override run => sub {
     my $self = shift;
-    my $server = $self->SUPER::setup_server();
-    $self->open_browser(url => 'http://localhost:'. $server->port);
-    return $server;
-}
+    $self->server;  # make sure server is initialised to not delay later
+
+    Prophet::CLI->end_pager();
+    print "Browser will be opened after server has been started.\n";
+    $self->open_browser(url => 'http://localhost:'. $self->server->port);
+    $self->SUPER::run();
+};
 
 sub open_browser {
     my $self = shift;
@@ -21,9 +24,14 @@ sub open_browser {
     }
 
     if ($args{url}) {
-        return if fork != 0;
-        sleep 2;
-        exec($opener, $args{url}) or die "Couldn't exec $opener: $!";
+        defined (my $child_pid = fork) or die "Cannot fork: $!\n";
+        if ( $child_pid == 0 ) {
+            # child runs this block
+            sleep 2;
+            exec($opener, $args{url}) or die "Couldn't exec $opener: $!";
+            exit(0);
+        }
+        return;     # parent just returns to run the server
     }
 }
 
diff --git a/lib/App/SD/CLI/Command/Server.pm b/lib/App/SD/CLI/Command/Server.pm
index c4194f1..c4f2217 100644
--- a/lib/App/SD/CLI/Command/Server.pm
+++ b/lib/App/SD/CLI/Command/Server.pm
@@ -4,11 +4,9 @@ extends 'Prophet::CLI::Command::Server';
 
 sub run {
     my $self = shift;
-    my $server = $self->setup_server();
-    $server->read_only(1) unless ($self->has_arg('writable'));
-    Prophet::CLI->end_pager();
+    $self->server->read_only(1) unless ($self->has_arg('writable'));
 
-    $server->run;
-}   
+    $self->SUPER::run();
+}
 
 1;

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list