Permalink
Browse files

not needed anymore

  • Loading branch information...
1 parent b826f21 commit 766caf4c77243c016a4e3330c423ebb91c11f9cd @nics nics committed May 7, 2012
Showing with 0 additions and 61 deletions.
  1. +0 −61 lib/Template/Plugin/Lookup.pm
@@ -1,61 +0,0 @@
-package Template::Plugin::Lookup;
-
-use strict;
-use warnings;
-use parent qw(Template::Plugin);
-use Hash::Util::FieldHash qw(fieldhash);
-
-fieldhash my %memo;
-
-sub new {
- my ($class, $context) = @_;
- bless {}, $class;
-}
-
-sub list {
- my ($self, $list) = @_;
- $memo{$list} ||= $self->index_list($list);
-}
-
-sub index_list {
- my ($self, $list, $index) = @_;
- $index ||= {};
- for my $item (@$list) {
- $index->{$item->{id}} = $item;
- if (my $children = $item->{children}) {
- $self->index_list($children, $index);
- }
- }
- $index;
-}
-
-1;
-
-=head1 NAME
-
-Template::Plugin::Lookup - Template plugin to index a list or tree of hashes
-
-=head1 SYNOPSIS
-
- $departments = [
- {
- id => 'FacSci',
- name => 'Faculty of Science',
- children => [
- {
- id => 'DepMat',
- name => 'Department of Mathematics',
- },
- ],
- },
- ]
-
- [% USE Lookup %]
- [% lookup = Lookup.list(departments) %]
- [% lookup.item('DepMat').name %]
-
-=head1 DESCRIPTION
-
-Template plugin to index a list or tree of hashes by it's id key in an inverse hash.
-
-=cut

0 comments on commit 766caf4

Please sign in to comment.