[Jifty-commit] r7150 - jifty/trunk/lib/Jifty

Jifty commits jifty-commit at lists.jifty.org
Mon Jun 1 19:52:09 EDT 2009


Author: sartak
Date: Mon Jun  1 19:52:09 2009
New Revision: 7150

Modified:
   jifty/trunk/lib/Jifty/Config.pm

Log:
Config->contextual_get

Modified: jifty/trunk/lib/Jifty/Config.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Config.pm	(original)
+++ jifty/trunk/lib/Jifty/Config.pm	Mon Jun  1 19:52:09 2009
@@ -77,6 +77,31 @@
 # A teeny helper for framework and app
 sub _get { return $_[0]->stash->{ $_[1] }{ $_[2] } }
 
+=head2 contextual_get CONTEXT VARIABLE
+
+Gets the configuration variable in the context C<CONTEXT>. The C<CONTEXT> is a
+slash-separated list of hash keys. For example, the following might return
+C<SQLite>:
+
+    contextual_get('/framework/Database', 'Driver')
+
+=cut
+
+sub contextual_get {
+    my $self    = shift;
+    my $context = shift;
+    my $field   = shift;
+
+    my $pointer = $self->stash;
+
+    my @fragments = grep { length } split '/', $context;
+    for my $fragment (@fragments) {
+        $pointer = $pointer->{$fragment} || return;
+    }
+
+    return $pointer->{$field};
+}
+
 =head1 LOADING
 
 =head2 new PARAMHASH


More information about the Jifty-commit mailing list