Browse files

Documenting and cleaning up the lookup method.

  • Loading branch information...
1 parent 30d0f84 commit ddd57ef4829be0276e45573a793aabe461e8c630 @pvande committed Jan 5, 2011
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/Template/Mustache.pm
View
12 lib/Template/Mustache.pm
@@ -201,21 +201,21 @@ sub generate {
} @$parse_tree;
}
+# Performs a lookup of a `$field` in a context stack.
+# @param [String] $field The field to lookup.
+# @param [(Any)] @context The context stack.
+# @return [(Any, Any)] The context element and value for the given `$field`.
+# @api private
sub lookup {
my ($field, @context) = @_;
- my $ctx;
- my $value = '';
+ my ($value, $ctx) = '';
for my $index (0..$#{[@context]}) {
$ctx = $context[$index];
if (ref $ctx eq 'HASH') {
next unless exists $ctx->{$field};
$value = $ctx->{$field};
last;
- } else {
- next unless UNIVERSAL::can($ctx, $field);
- $value = UNIVERSAL::can($ctx, $field)->();
- last;
}
}

0 comments on commit ddd57ef

Please sign in to comment.