-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f43d8a
commit 6a01f03
Showing
7 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.precomp | ||
.gitconfig | ||
sdist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use MONKEY-TYPING; | ||
use Humming-Bird::Plugin; | ||
use Humming-Bird::Core; | ||
|
||
unit class Humming-Bird::Plugin::DBIish does Humming-Bird::Plugin; | ||
|
||
my %databases; | ||
|
||
method register($server, %routes, @middleware, @advice, **@args) { | ||
my $database-name = 'default'; | ||
my @database-args; | ||
|
||
if @args.elems == 1 { | ||
if @args[0].isa(Array) || @args[0].isa(List) { | ||
@database-args = |@args[0]; | ||
} else { | ||
$database-name = @args[0]; | ||
} | ||
} else { | ||
$database-name = @args[0]; | ||
@database-args = |@args[1]; | ||
} | ||
|
||
try { | ||
require ::('DBIish'); | ||
CATCH { | ||
default { | ||
die 'DBIish is not installed, to use Humming-Bird::Plugin::DBIish, please install DBIish. "zef install DBIish"' | ||
} | ||
} | ||
} | ||
|
||
without @database-args { | ||
die 'Invalid configuration for Humming-Bird::Plugin::DBIish, please provide arguments.' | ||
} | ||
|
||
if (%databases.keys.elems == 0) { | ||
augment class Humming-Bird::Glue::HTTPAction { | ||
method db(Str $database = 'default') { | ||
%databases{$database}; | ||
} | ||
} | ||
} | ||
|
||
use DBIish; | ||
%databases{$database-name} = DBIish.connect(|@database-args); | ||
|
||
CATCH { | ||
default { | ||
die 'Failed to setup Humming-Bird::Plugin::DBIish cause: $_'; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use MONKEY-TYPING; | ||
use Humming-Bird::Plugin; | ||
use Humming-Bird::Core; | ||
use Humming-Bird::Backend; | ||
|
||
unit class Humming-Bird::Plugin::HotReload does Humming-Bird::Plugin; | ||
|
||
class Humming-Bird::Backend::HotReload does Humming-Bird::Backend { | ||
has $.backend handles <port addr timeout>; | ||
has Channel:D $!reload-chan .= new; | ||
method listen(&handler) { | ||
self!observe(); | ||
self!start-server(); | ||
|
||
react whenever $!reload-chan -> $reload { | ||
$.backend.close; | ||
self!start-server(); | ||
} | ||
} | ||
|
||
method !start-server { | ||
start { | ||
listen(self.port, self.addr, ); | ||
} | ||
} | ||
|
||
method !observe { | ||
|
||
} | ||
} | ||
|
||
method register($server is rw, %routes, @middleware, @advice, **@args) { | ||
$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.'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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; | ||
use Humming-Bird::Plugin::DBIish; | ||
|
||
try { | ||
require ::('DBIish'); | ||
|
||
CATCH { | ||
default { | ||
warn 'DBIish not installed, skipping Humming-Bird::Plugin::DBIish tests.'; | ||
skip-rest; | ||
} | ||
} | ||
} | ||
|
||
use DBDish::TestMock::Connection; | ||
|
||
class TestBackend does Humming-Bird::Backend { | ||
method listen(&handler) { | ||
return; # Does nothing | ||
} | ||
} | ||
|
||
lives-ok sub { plugin('DBIish', ['TestMock']); }, 'Does default plugin not die?'; | ||
lives-ok sub { plugin('DBIish', 'other-db', ['TestMock']); }, 'Does other-db plugin not die?';\ | ||
lives-ok sub { listen(8080, :backend(TestBackend)); }, 'Does plugin register ok?'; | ||
ok Humming-Bird::Glue::HTTPAction.^can('db'), 'Did plugin properly run?'; | ||
my $action = Humming-Bird::Glue::HTTPAction.new; | ||
|
||
ok $action.^can('db')[0].($action); | ||
ok $action.^can('db')[0].($action, 'other-db'); | ||
ok $action.^can('db')[0].($action).isa(DBDish::TestMock::Connection); | ||
ok $action.^can('db')[0].($action, 'other-db').isa(DBDish::TestMock::Connection); | ||
|
||
done-testing; |