/[webpac2]/trunk/lib/WebPAC/Output/TT.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Output/TT.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 42 by dpavlin, Mon Nov 14 16:11:40 2005 UTC revision 62 by dpavlin, Tue Nov 15 14:31:12 2005 UTC
# Line 73  Create output from in-memory data struct Line 73  Create output from in-memory data struct
73          data => \@ds          data => \@ds
74   );   );
75    
76    It also has follwing template toolikit filter routies defined:
77    
78  =cut  =cut
79    
80  sub apply {  sub apply {
# Line 86  sub apply { Line 88  sub apply {
88                  $log->logconfess("need $a") unless ($args->{$a});                  $log->logconfess("need $a") unless ($args->{$a});
89          }          }
90    
91          # filter to return value from @ds  =head3 tt_filter_type
   
         sub tt_filter_d {  
   
                 my ($name,$join) = @_;  
   
 print "### name = ",Dumper($name);  
92    
93                  my $item = first { $_->{'name'} eq $name } @{ $args->{'data'} };  filter to return values of specified from @ds
94    
95                  return unless($item);  =cut
   
 print "### item = ",Dumper($item);  
   
                 my $v = $item->{'display'} || return;  
96    
97                  if (ref($v) eq 'ARRAY') {          sub tt_filter_type {
98                          if ($#{$v} == 0) {                  my ($data,$type) = @_;
99                                  $v = $v->[0];                  
100                          } else {                  die "no data?" unless ($data);
101                                  $join = '&#182;<br/>' unless defined($join);                  $type ||= 'display';
102                                  $v = join($join, @{$v});  
103                    my $default_delimiter = {
104                            'display' => '&#182;<br/>',
105                            'index' => '\n',
106                    };
107    
108                    return sub {
109    
110                            my ($name,$join) = @_;
111    
112                            die "no data array" unless ($data->{'data'} && ref($data->{'data'}) eq 'ARRAY');
113                            # Hm? Should we die here?
114                            return unless ($name);
115    
116                            my $item = first { $_->{'name'} eq $name } @{ $data->{'data'} };
117    
118                            return unless($item);
119    
120                            my $v = $item->{$type} || return;
121    
122                            if (ref($v) eq 'ARRAY') {
123                                    if ($#{$v} == 0) {
124                                            $v = $v->[0];
125                                    } else {
126                                            $join = $default_delimiter->{$type} unless defined($join);
127                                            $v = join($join, @{$v});
128                                    }
129                          }                          }
130    
131                            return $v;
132                  }                  }
 print "### v = $v\n";  
                 return $v;  
133          }          }
         $args->{'d'} = \&tt_filter_d;  
134    
135            $args->{'d'} = tt_filter_type($args, 'display');
136    
137          my $out;          my $out;
138    

Legend:
Removed from v.42  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.26