Skip to content

Commit

Permalink
index/module を実行時にキャッシュする形に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kfly8 committed Dec 6, 2023
1 parent dcfdccb commit 23071bc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 43 deletions.
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 23071bc

Please sign in to comment.