diff --git a/META6.json b/META6.json index 6166ecd..b4f21fe 100644 --- a/META6.json +++ b/META6.json @@ -29,7 +29,12 @@ "Humming-Bird::Plugin::Config": "lib/Humming-Bird/Plugin/Config.rakumod", "Humming-Bird::Plugin::Logger": "lib/Humming-Bird/Plugin/Logger.rakumod", "Humming-Bird::Plugin::Session": "lib/Humming-Bird/Plugin/Session.rakumod", +<<<<<<< HEAD "Humming-Bird::Plugin::DBIish": "lib/Humming-Bird/Plugin/DBIish.rakumod" +======= + "Humming-Bird::Plugin::DBIish": "lib/Humming-Bird/Plugin/DBIish.rakumod", + "Humming-Bird::Plugin::HotReload": "lib/Humming-Bird/Plugin/HotReload.rakumod" +>>>>>>> dbiish }, "resources": [ ], diff --git a/lib/Humming-Bird/Backend/HTTPServer.rakumod b/lib/Humming-Bird/Backend/HTTPServer.rakumod index b245fd8..eb22d2b 100644 --- a/lib/Humming-Bird/Backend/HTTPServer.rakumod +++ b/lib/Humming-Bird/Backend/HTTPServer.rakumod @@ -17,6 +17,12 @@ my constant $RN = "\r\n".encode.Buf; has Channel:D $.requests .= new; has Lock $!lock .= new; has @!connections; +has $!conn-channel; + +method close { + $_.close for @!connections; + $!conn-channel.close; +} method !timeout { start { @@ -69,7 +75,8 @@ method listen(&handler) { react { self!timeout; self!respond(&handler); - whenever IO::Socket::Async.listen($.addr // '0.0.0.0', $.port) -> $connection { + $!conn-channel = IO::Socket::Async.listen($.addr // '0.0.0.0', $.port).Channel; + whenever $!conn-channel -> $connection { my %connection-map := { socket => $connection, last-active => now diff --git a/lib/Humming-Bird/Plugin/DBIish.rakumod b/lib/Humming-Bird/Plugin/DBIish.rakumod index c4d1530..d292ff8 100644 --- a/lib/Humming-Bird/Plugin/DBIish.rakumod +++ b/lib/Humming-Bird/Plugin/DBIish.rakumod @@ -41,7 +41,6 @@ method register($server, %routes, @middleware, @advice, **@args) { my $dh = $dbiish.install-driver(shift @database-args); - say @database-args; %databases{$database-name} = $dh.connect(|%(|@database-args)); CATCH { diff --git a/lib/Humming-Bird/Plugin/HotReload.rakumod b/lib/Humming-Bird/Plugin/HotReload.rakumod index 72689a0..0dcf524 100644 --- a/lib/Humming-Bird/Plugin/HotReload.rakumod +++ b/lib/Humming-Bird/Plugin/HotReload.rakumod @@ -13,28 +13,27 @@ class Humming-Bird::Backend::HotReload does Humming-Bird::Backend { self!start-server(); react whenever $!reload-chan -> $reload { - $.backend.close; - self!start-server(); + if ($reload === True) { + $.backend.close; + self!start-server(); + } } } method !start-server { start { - listen(self.port, self.addr, ); + listen(self.port, self.addr); } } method !observe { - + react whenever IO::Notification.watch-path('.') { + say "$^file changed, reloading Humming-Bird..."; + $!reload-chan.send: True; + } } } method register($server is rw, %routes, @middleware, @advice, **@args) { - die 'Humming-Bird::Backend::HotRealod is WIP. Please do not use it yet.'; - $server = Humming-Bird::Backend::HotReload.new(backend => $server); - CATCH { - default { - warn 'Failed to find or parse your ".humming-bird.json" configuration. Ensure your file is well formed, and does exist.'; - } - } + $server := Humming-Bird::Backend::HotReload.new(backend => $server, timeout => 3); } diff --git a/t/13-plugin.rakutest b/t/13-plugin.rakutest index 7d9f035..02b0063 100644 --- a/t/13-plugin.rakutest +++ b/t/13-plugin.rakutest @@ -15,9 +15,9 @@ class TestBackend does Humming-Bird::Backend { } } -lives-ok sub { plugin('Config', 't/static/.humming-bird.json'); }, 'Does plugin not die?'; -lives-ok sub { plugin 'Logger'; }, 'Does other plugin not die?'; -lives-ok sub { plugin 'Session'; }, 'Does other plugin not die?'; +lives-ok sub { plugin('Config', 't/static/.humming-bird.json'); }, 'Does Config plugin not die?'; +lives-ok sub { plugin 'Logger'; }, 'Does Logger plugin not die?'; +lives-ok sub { plugin 'Session'; }, 'Does Session plugin not die?'; lives-ok sub { listen(8080, :backend(TestBackend)); }, 'Does plugin register ok?'; ok Humming-Bird::Glue::HTTPAction.^can('config'), 'Did plugin properly run?'; diff --git a/t/14-hotreload.rakutest b/t/14-hotreload.rakutest new file mode 100644 index 0000000..124a3f3 --- /dev/null +++ b/t/14-hotreload.rakutest @@ -0,0 +1,12 @@ +use v6; +use lib 'lib'; +use Test; +use Humming-Bird::Core; +use Humming-Bird::Glue; +use Humming-Bird::Backend; +use Humming-Bird::Middleware; +use Humming-Bird::Advice; + +plan 1; + +lives-ok { plugin 'HotReload' }, 'Does HotReload plugin live ok?';