r958@llin: dpavlin | 2006-09-24 17:26:37 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Sep 2006 15:28:54 +0000 (15:28 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Sep 2006 15:28:54 +0000 (15:28 +0000)
 added $config->get and $config->webpac

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@682 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Config.pm
t/1-config.t
t/conf/test.yml [new file with mode: 0644]

index b5ded54..49214b2 100644 (file)
@@ -89,6 +89,42 @@ sub use_indexer {
        return $self->{config}->{use_indexer} || $default;
 }
 
+=head2 get
+
+  $config->get('top-level_key');
+
+=cut
+
+sub get {
+       my $self = shift;
+       my $what = shift || return;
+       return $self->{config}->{$what};
+}
+
+=head2 webpac
+
+Return C<< config -> webpac >> parts
+
+  my @supported_inputs = $config->webpac('inputs');
+  my $inputs_hash = $config->webpac('inputs');
+
+=cut
+
+sub webpac {
+       my $self = shift;
+
+       $self->_get_logger()->logdie("can't find config->webpac") unless defined( $self->{config}->{webpac} );
+
+       my $what = shift || return $self->{config}->{webpac};
+
+       if (wantarray) {
+               return keys %{ $self->{config}->{webpac}->{$what} };
+       } else {
+               return $self->{config}->{webpac}->{$what};
+       }
+
+}
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
index 7385022..f7ff11e 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 8;
+use Test::More tests => 12;
 use Test::Exception;
 use blib;
 
@@ -19,16 +19,24 @@ $abs_path =~ s#/[^/]*$#/#;
 
 my $path = "$abs_path/conf/test.yml";
 
-ok(my $c = new WebPAC::Config( path => $path ), "new");
+ok(my $config = new WebPAC::Config( path => $path ), "new");
 
-cmp_ok($c->{path}, 'eq', $path, "path $path");
+cmp_ok($config->{path}, 'eq', $path, "path $path");
 
-ok($c->{config}, "config exist");
+ok($config->{config}, "config exist");
 
-isa_ok($c->databases, 'HASH', "databases");
-
-my @names = $c->databases;
+# $config->databases
 
+isa_ok($config->databases, 'HASH', "databases");
+my @names = $config->databases;
 isa_ok(\@names, 'ARRAY', "databases names");
-
 cmp_ok(@names, '==', 3, "got 3 names");
+isa_ok($config->databases, 'HASH', "databases");
+
+diag '$config->webpac = ', dump($config->webpac) if ($debug);
+
+isa_ok($config->webpac, 'HASH', "webpac");
+my @inputs = $config->webpac('inputs');
+diag "inputs = ",dump( @inputs ) if ($debug);
+isa_ok(\@inputs, 'ARRAY', "inputs");
+cmp_ok(@inputs, '==', 2, "got 2 webpac inputs");
diff --git a/t/conf/test.yml b/t/conf/test.yml
new file mode 100644 (file)
index 0000000..86a8854
--- /dev/null
@@ -0,0 +1,41 @@
+--- #YAML:1.0
+# DO NOT USE TABS FOR INDENTATION OR label/value SEPARATION!!!
+
+webpac:
+  inputs:
+    isis: 'WebPAC::Input::ISIS'
+    marc: 'WebPAC::Input::MARC'
+
+databases:
+  foo:
+    name: 'foo name'
+    input:
+      name: 'foo-input1'
+      type: isis
+      path: '/backup/isis_backup/A105-1/ISIS/latest/LIBRI/LIBRI'
+      encoding: 'cp852'
+      #limit: 10
+      normalize:
+        path: 'conf/normalize/foo.pl'
+
+  bar:
+    name: 'bar name'
+    input:
+      name: 'bar-input1'
+      type: isis
+      path: '/backup/isis_backup/A105-1/ISIS/latest/LIBRI/LIBRI'
+      encoding: 'cp852'
+      #limit: 10
+      normalize:
+        path: 'conf/normalize/bar.pl'
+
+  baz:
+    name: 'baz name'
+    input:
+      name: 'baz-input1'
+      type: isis
+      path: '/backup/isis_backup/A105-1/ISIS/latest/LIBRI/LIBRI'
+      encoding: 'cp852'
+      #limit: 10
+      normalize:
+        path: 'conf/normalize/baz.pl'