]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
Upd. More cache type compatible.
authorWill Budic <redacted>
Fri, 6 Mar 2026 02:12:44 +0000 (13:12 +1100)
committerWill Budic <redacted>
Fri, 6 Mar 2026 02:12:44 +0000 (13:12 +1100)
system/modules/CNFGlobalFile.pm

index 3e8f7155c88d272bd3155d1145d5b0e53c72f744..d9f14f6ea846b0f31bd6664beb3b42a66d2a9527 100644 (file)
@@ -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;
 }