Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information...
commit 1584c0a6366baaf18be0c6783784553e7143e376 1 parent d871923
@melo authored
View
17 lib/Logan/Config/Static.pm
@@ -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
20 t/40-config-static.t
@@ -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();
View
9 t/tlib/T/Config/Static.pm
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.