Permalink
Browse files

Added basic configuration role for Logan's: accepts a config HashRef

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information...
1 parent d871923 commit 1584c0a6366baaf18be0c6783784553e7143e376 @melo committed Aug 3, 2012
Showing with 46 additions and 0 deletions.
  1. +17 −0 lib/Logan/Config/Static.pm
  2. +20 −0 t/40-config-static.t
  3. +9 −0 t/tlib/T/Config/Static.pm
View
@@ -0,0 +1,17 @@
+package Logan::Config::Static;
+
+use Moo::Role;
+use namespace::autoclean;
+
+has '_cfg' => (is => 'ro', default => sub { {} }, init_arg => 'config');
+
+sub config {
+ my $self = shift;
+ my $cfg = $self->_cfg;
+
+ return $cfg unless @_;
+ return unless exists $cfg->{ $_[0] };
+ return $cfg->{ $_[0] };
+}
+
+1;
View
@@ -0,0 +1,20 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Deep;
+use lib 't/tlib';
+use T::Config::Static;
+
+my $l = T::Config::Static->setup;
+cmp_deeply($l->config, {}, 'config() is empty by default');
+is($l->config('boo'), undef, '... so asking for something that doesnt exist, returns undef');
+
+$l = T::Config::Static->setup(config => { answer => 42 });
+cmp_deeply($l->config, { answer => 42 }, 'config() returns the full config now');
+is($l->config('boo'), undef, '... but asking for something that doesnt exist, still undef');
+is($l->config('answer'), 42, 'asking for something that is there returns the expected value');
+
+
+done_testing();
@@ -0,0 +1,9 @@
+package T::Config::Static;
+
+use Moo;
+extends 'T::Logan::Queued';
+with 'Logan::Config::Static';
+
+sub default_no_filter_should_dispatch {1}
+
+1;

0 comments on commit 1584c0a

Please sign in to comment.