/[webpac2]/Webpacus/lib/Webpacus/Model/WebPAC.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 /Webpacus/lib/Webpacus/Model/WebPAC.pm

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

revision 355 by dpavlin, Sat Jan 7 22:45:16 2006 UTC revision 378 by dpavlin, Sat Jan 21 23:27:16 2006 UTC
# Line 6  use lib '/data/webpac2/lib'; Line 6  use lib '/data/webpac2/lib';
6  use base qw/  use base qw/
7          Catalyst::Model          Catalyst::Model
8  /;  /;
 use Data::Dumper;  
9  use WebPAC::Store 0.08;  use WebPAC::Store 0.08;
 use WebPAC::Output::TT 0.07;  
10  use WebPAC::Search::Estraier 0.05;  use WebPAC::Search::Estraier 0.05;
11  use File::Slurp;  use File::Slurp;
12  use Time::HiRes;  use Time::HiRes qw/time/;
13  use Encode qw/encode decode from_to/;  use Encode qw/encode decode from_to/;
14  use Data::HTMLDumper;  use Data::Dumper;
15    
16  =head1 NAME  =head1 NAME
17    
# Line 94  sub new { Line 92  sub new {
92                  database => $est_cfg->{database},                  database => $est_cfg->{database},
93          );          );
94    
         $self->{out} = new WebPAC::Output::TT(  
                 include_path => $template_path,  
                 filters => {  
                         dump_html => sub {  
                                 return unless (@_);  
                                 my $out;  
                                 my $i = 1;  
                                 foreach my $v (@_) {  
                                         $out .= qq{<div id="dump_$i">} .  
                                                 Data::HTMLDumper->Dump([ $v ],[ "v$i" ]) .  
                                                 qq{</div>};  
                                         $i++;  
                                 }  
                                 $out =~ s!<table[^>/]*>!<table class="dump">!gis if ($out);  
                                 return $out;  
                         }  
                 },  
         );  
   
95          # default template from config.yaml          # default template from config.yaml
96          $self->{template} ||= $c->config->{webpac}->{template};          $self->{template} ||= $c->config->{webpac}->{template};
97    
# Line 123  sub new { Line 102  sub new {
102    
103          $self->{databases} = $c->config->{databases} || $log->error("can't find databases in config");          $self->{databases} = $c->config->{databases} || $log->error("can't find databases in config");
104    
105            $self->{model_record} = $c->comp('Model::Record') or $log->error("can't find Model::Record");
106    
107          return $self;          return $self;
108    
109  }  }
# Line 148  selected template. Line 129  selected template.
129  sub search {  sub search {
130          my $self = shift;          my $self = shift;
131    
132            my $search_start_t = time();
133    
134          my $args = {@_};          my $args = {@_};
135    
136          my $log = $self->{log};          my $log = $self->{log};
# Line 188  sub search { Line 171  sub search {
171    
172          my $hits = $#results + 1;          my $hits = $#results + 1;
173    
174          $log->debug( sprintf("search took %.2fs and returned $hits hits.", $times->{est}) );          $log->debug( sprintf("search took %.6fs and returned $hits hits.", $times->{est}) );
175    
176          # just return results?          # just return results?
177          return @results unless ($args->{'template'});          return @results unless ($args->{'template'});
# Line 225  sub search { Line 208  sub search {
208    
209                  $t = time();                  $t = time();
210    
211                  my $html = $self->{out}->apply(                  my $html = '[no output]';
212                          template => $template_filename,  
213                          data => $ds,                  if ($self->{model_record}) {
214                          record_uri => "${database}/${prefix}/${id}",                          $html = $self->{model_record}->apply(
215                          config => $self->{databases}->{$database},                                  template => $template_filename,
216                  );                                  data => $ds,
217                                    record_uri => "${database}/${prefix}/${id}",
218                                    config => $self->{databases}->{$database},
219                            );
220                    } else {
221                            $log->warn("skipped apply");
222                    }
223    
224                  $times->{out} += time() - $t;                  $times->{out} += time() - $t;
225    
# Line 245  sub search { Line 234  sub search {
234          #$log->debug( '@html_results = ' . Dumper( \@html_results ) );          #$log->debug( '@html_results = ' . Dumper( \@html_results ) );
235    
236          $log->debug( sprintf(          $log->debug( sprintf(
237                  "time spent: db = %.2f, out = %.2f",                  "duration breakdown: store %.6fs, apply %.6fs, total: %.6fs",
238                  $times->{db}, $times->{out},                  $times->{db}, $times->{out}, time() - $search_start_t,
239          ) );          ) );
240    
241          return \@html_results;          return \@html_results;
# Line 290  sub record { Line 279  sub record {
279                  return;                  return;
280          }          }
281    
282          my $html = $self->{out}->apply(          my $html = $self->{model_record}->apply(
283                  template => $args->{template},                  template => $args->{template},
284                  data => $ds,                  data => $ds,
285                  record_uri => $args->{record_uri},                  record_uri => $args->{record_uri},

Legend:
Removed from v.355  
changed lines
  Added in v.378

  ViewVC Help
Powered by ViewVC 1.1.26