diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-12-28 13:50:27 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-12-28 13:50:45 -0600 |
commit | 0dca94214cbf0cd77a75d1ddb285ada5306be67e (patch) | |
tree | 2b8aba6e5a945ca73c6f21eb3e6a9caff7653ae0 /t | |
parent | 005699bf2fb916ab532f360e37d190c1a7602ec7 (diff) | |
download | p6-bread-board-0dca94214cbf0cd77a75d1ddb285ada5306be67e.tar.gz p6-bread-board-0dca94214cbf0cd77a75d1ddb285ada5306be67e.zip |
implement some bread::board sugar
Diffstat (limited to 't')
-rw-r--r-- | t/020_sugar.t | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/t/020_sugar.t b/t/020_sugar.t new file mode 100644 index 0000000..04074fd --- /dev/null +++ b/t/020_sugar.t @@ -0,0 +1,48 @@ +use v6; +use Test; + +use Bread::Board; + +class FileLogger { + has $.log_file; +} + +class MyApplication { + has FileLogger $.logger; +} + +my $c = container 'MyApp', { + service 'log_file', 'logfile.log'; + + service 'logger', ( + class => FileLogger, + lifecycle => Singleton, + dependencies => { + log_file => depends_on('log_file'), + }, + ); + + service 'application', ( + class => MyApplication, + dependencies => { + logger => depends_on('logger'), + }, + ); +}; + +#my $logger = $c.resolve(service => 'logger'); +my $logger = $c.fetch('logger').get; +isa_ok($logger, FileLogger); +is($logger.log_file, 'logfile.log'); + +is($c.fetch('logger/log_file').service, $c.fetch('log_file')); +is($c.fetch('logger/log_file').get, 'logfile.log'); + +my $app = $c.resolve(service => 'application'); +isa_ok($app, MyApplication); +isa_ok($app.logger, FileLogger); +is($app.logger, $logger); + +done; + +# vim:ft=perl6:foldmethod=manual |