/[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 43 by dpavlin, Mon Nov 14 16:12:01 2005 UTC revision 70 by dpavlin, Sat Nov 19 23:48:24 2005 UTC
# Line 70  Create output from in-memory data struct Line 70  Create output from in-memory data struct
70    
71   my $text = $tt->apply(   my $text = $tt->apply(
72          template => 'text.tt',          template => 'text.tt',
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
92    
93    filter to return values of specified from $ds
94    
95    =cut
96    
97          sub tt_filter_type {          sub tt_filter_type {
98                  my ($data,$type) = @_;                  my ($data,$type) = @_;
# Line 101  sub apply { Line 107  sub apply {
107    
108                  return sub {                  return sub {
109    
 print "### data = ",Dumper($data);  
   
110                          my ($name,$join) = @_;                          my ($name,$join) = @_;
111    
112                          die "no data array" unless ($data->{'data'} && ref($data->{'data'}) eq 'ARRAY');                          die "no data hash" unless ($data->{'data'} && ref($data->{'data'}) eq 'HASH');
113                            # Hm? Should we die here?
114                            return unless ($name);
115    
116  print "### name, join = ",Dumper($name);                          my $item = $data->{'data'}->{$name} || return;
   
                         my $item = first { $_->{'name'} eq $name } @{ $data->{'data'} };  
   
                         return unless($item);  
   
 print "### item = ",Dumper($item);  
117    
118                          my $v = $item->{$type} || return;                          my $v = $item->{$type} || return;
119    
# Line 125  print "### item = ",Dumper($item); Line 125  print "### item = ",Dumper($item);
125                                          $v = join($join, @{$v});                                          $v = join($join, @{$v});
126                                  }                                  }
127                          }                          }
128  print "### v = $v\n";  
129                          return $v;                          return $v;
130                  }                  }
131          }          }
# Line 151  to a file. Line 151  to a file.
151   $tt->to_file(   $tt->to_file(
152          file => 'out.txt',          file => 'out.txt',
153          template => 'text.tt',          template => 'text.tt',
154          data => \@ds          data => $ds
155   );   );
156    
157  =cut  =cut

Legend:
Removed from v.43  
changed lines
  Added in v.70

  ViewVC Help
Powered by ViewVC 1.1.26