/[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 16 by dpavlin, Sun Jul 17 11:37:07 2005 UTC revision 43 by dpavlin, Mon Nov 14 16:12:01 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 67  sub new { Line 68  sub new {
68    
69  Create output from in-memory data structure using Template Toolkit template.  Create output from in-memory data structure using Template Toolkit template.
70    
71  my $text = $tt->apply( template => 'text.tt', data => @ds );   my $text = $tt->apply(
72            template => 'text.tt',
73            data => \@ds
74     );
75    
76  =cut  =cut
77    
# Line 82  sub apply { Line 86  sub apply {
86                  $log->logconfess("need $a") unless ($args->{$a});                  $log->logconfess("need $a") unless ($args->{$a});
87          }          }
88    
89            # filter to return value from @ds
90    
91            sub tt_filter_type {
92                    my ($data,$type) = @_;
93                    
94                    die "no data?" unless ($data);
95                    $type ||= 'display';
96    
97                    my $default_delimiter = {
98                            'display' => '&#182;<br/>',
99                            'index' => '\n',
100                    };
101    
102                    return sub {
103    
104    print "### data = ",Dumper($data);
105    
106                            my ($name,$join) = @_;
107    
108                            die "no data array" unless ($data->{'data'} && ref($data->{'data'}) eq 'ARRAY');
109    
110    print "### name, join = ",Dumper($name);
111    
112                            my $item = first { $_->{'name'} eq $name } @{ $data->{'data'} };
113    
114                            return unless($item);
115    
116    print "### item = ",Dumper($item);
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    print "### v = $v\n";
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 101  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.16  
changed lines
  Added in v.43

  ViewVC Help
Powered by ViewVC 1.1.26