/[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 21 by dpavlin, Sun Jul 17 22:28:11 2005 UTC revision 70 by dpavlin, Sat Nov 19 23:48:24 2005 UTC
# Line 6  use strict; Line 6  use strict;
6  use base qw/WebPAC::Common/;  use base qw/WebPAC::Common/;
7    
8  use Template;  use Template;
9    use List::Util qw/first/;
10  use Data::Dumper;  use Data::Dumper;
11    
12  =head1 NAME  =head1 NAME
# Line 69  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 85  sub apply { Line 88  sub apply {
88                  $log->logconfess("need $a") unless ($args->{$a});                  $log->logconfess("need $a") unless ($args->{$a});
89          }          }
90    
91    =head3 tt_filter_type
92    
93    filter to return values of specified from $ds
94    
95    =cut
96    
97            sub tt_filter_type {
98                    my ($data,$type) = @_;
99                    
100                    die "no data?" unless ($data);
101                    $type ||= 'display';
102    
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 hash" unless ($data->{'data'} && ref($data->{'data'}) eq 'HASH');
113                            # Hm? Should we die here?
114                            return unless ($name);
115    
116                            my $item = $data->{'data'}->{$name} || return;
117    
118                            my $v = $item->{$type} || return;
119    
120                            if (ref($v) eq 'ARRAY') {
121                                    if ($#{$v} == 0) {
122                                            $v = $v->[0];
123                                    } else {
124                                            $join = $default_delimiter->{$type} unless defined($join);
125                                            $v = join($join, @{$v});
126                                    }
127                            }
128    
129                            return $v;
130                    }
131            }
132    
133            $args->{'d'} = tt_filter_type($args, 'display');
134    
135          my $out;          my $out;
136    
137          $self->{'tt'}->process(          $self->{'tt'}->process(
# Line 104  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.21  
changed lines
  Added in v.70

  ViewVC Help
Powered by ViewVC 1.1.26