From: Will Budic Date: Fri, 6 Mar 2026 02:12:44 +0000 (+1100) Subject: Upd. More cache type compatible. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=be015abf2cb1456aa97803af08e7abdd6b35219e;p=PerlCNF.git Upd. More cache type compatible. --- diff --git a/system/modules/CNFGlobalFile.pm b/system/modules/CNFGlobalFile.pm index 3e8f715..d9f14f6 100644 --- a/system/modules/CNFGlobalFile.pm +++ b/system/modules/CNFGlobalFile.pm @@ -6,15 +6,19 @@ # Open Source Code License -> https://choosealicense.com/licenses/isc/ # package CNFGlobalFile; -use strict; use warnings; no warnings qw(experimental::signatures); use feature qw(signatures say); +use strict; use warnings; +no warnings qw(experimental::signatures); use feature qw(signatures say); -sub new ($class, $path) { - my @stat = stat($path); - bless {path=>$path, content_length => $stat[7], last_modified => $stat[9]}, $class; +sub new { + my($class, $path) =@_; + my @stat = stat($path); + my $self = {path=>$path, content_length => $stat[7], last_modified => $stat[9]}; + bless $self, $class; + return $self; } sub content($self) { - return _load($self) -> {content} ; + return exists $self -> {content} ? $self -> {content} : load($self) -> {content} ; } sub changed($self){ return 1 if not $self->{last_modified}; #We return changed if doesn't exist. my @stats = stat($self->{path}); @@ -36,14 +40,15 @@ sub _binary($self, $handle){ $self -> {last_modified} = $stat[9]; return $self; } -sub _load($self){ - open(my $fh,'<:encoding(UTF-8)', $self->{path}) or die "Path: ".$self->{path}." not found!"; - read $fh, my $content, -s $fh; - close $fh; +sub load($self){ + open(my $fh,'<:encoding(UTF-8)', $self->{path}) or die "Path: ".$self->{path}." not found!"; + read $fh, my $content, -s $fh; + close $fh; + my @stat = stat($self->{path}); $self -> {content_date} = time; $self -> {content_length} = $stat[7]; - $self -> {content} = \$content; + $self -> {content} = \$content if $content; return $self; }