Skip to content

Commit

Permalink
Merge pull request #56 from perldoc-jp/remove-index-module-generate-a…
Browse files Browse the repository at this point in the history
…nd-save

index/module を実行時キャッシュにする
  • Loading branch information
kfly8 authored Dec 6, 2023
2 parents 5333d4e + 23071bc commit ba958df
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 43 deletions.
2 changes: 2 additions & 0 deletions lib/PJP/Cache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ sub file_cache {
sub get_or_set {
my ($self, $key, $cb, $xt) = @_;

$key .= rand() if $ENV{DEBUG};

my $val = $self->{cache}->get($key);
return $val if defined $val;

Expand Down
4 changes: 2 additions & 2 deletions lib/PJP/M/Index/Article.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ sub _generate {
};

if ($is_pod) {
infof("parsing %s", $file);
debugf("parsing %s", $file);
my ($name, $desc) = PJP::M::Pod->parse_name_section($file);
if ($desc) {
infof("Japanese Description: %s, %s", $name, $desc);
debugf("Japanese Description: %s, %s", $name, $desc);
$row->{abstract} = $desc;
}
}
Expand Down
39 changes: 2 additions & 37 deletions lib/PJP/M/Index/Module.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,6 @@ use File::Find::Rule;
use version;
use autodie;
use PJP::M::Pod;
use Data::Dumper;
use PJP::Util qw/slurp/;

sub get {
my ($class, $c) = @_;

my $fname = $class->cache_path($c);
unless (-f $fname) {
die "Missing '$fname'";
}

return do $fname;
}

sub cache_path {
my ($class, $c) = @_;
return catfile($c->assets_dir(), 'index-module.pl');
}

sub generate_and_save {
my ($class, $c) = @_;

my $fname = $class->cache_path($c);

my @data = $class->generate($c);
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Indent = 1;
local $Data::Dumper::Purity = 1;

open my $fh, '>', $fname;
print $fh Dumper(\@data);
close $fh;

return;
}

sub generate {
my ($class, $c) = @_;
Expand Down Expand Up @@ -151,10 +116,10 @@ sub _generate {
# pod file が一個もないものは表示しない(具体的には CPANPLUS)
next unless $pod_file;

infof("parsing %s", $pod_file);
debugf("parsing %s", $pod_file);
my ($name, $desc) = PJP::M::Pod->parse_name_section($pod_file);
if ($desc) {
infof("Japanese Description: %s, %s", $name, $desc);
debugf("Japanese Description: %s, %s", $name, $desc);
$row->{abstract} = $desc;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/PJP/Web/Dispatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ get '/index/variable' => sub {
get '/index/module' => sub {
my $c = shift;

my $content = $c->cache->file_cache("index/module", PJP::M::Index::Module->cache_path($c), sub {
my $index = PJP::M::Index::Module->get($c);
my $content = $c->cache->get_or_set('index/module', sub {
my @data = PJP::M::Index::Module->generate($c);
$c->create_view->render(
'index/module.tt' => {
index => $index,
index => \@data,
}
);
});
Expand Down
1 change: 0 additions & 1 deletion script/update.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
}

my $t = time;
PJP::M::Index::Module->generate_and_save($pjp);
PJP::M::BuiltinFunction->generate($pjp);
PJP::M::BuiltinVariable->generate($pjp);
PJP::M::PodFile->generate($pjp);
Expand Down

0 comments on commit ba958df

Please sign in to comment.