]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
new. feature conventional script name loading of with FILE command with $0.
authorWill Budic <redacted>
Tue, 23 Sep 2025 12:46:03 +0000 (22:46 +1000)
committerWill Budic <redacted>
Tue, 23 Sep 2025 12:46:03 +0000 (22:46 +1000)
system/modules/CNFParser.pm

index 3ef1efdc947c002fa156c6bc0723c100a7943c14..a60beff0fa5961d532cab0db87328612d53ca12e 100644 (file)
@@ -666,10 +666,20 @@ sub doInstruction { my ($self,$e,$t,$v,$is_tagged) = @_;
         }
     }
 }
+
 sub doLoadDataFile { my ($self,$e,$v)=@_;
         my ($path,$cnf_file) = ("",$self->{CNF_CONTENT});
-        $v=~s/\s+//g;
-        if(! -e $v){
+        $v=~s/\s+//g; 
+        if ($v eq '$0'){ 
+            $path = $0; $path =~ m/.*\/(.*)\..*$/ ; $path = $ENV{HOME}."/.config/$1.cnf";
+            if( -e $path ){
+                $self ->parse($path)                
+            }else{
+                $self->warn("Skipping conventional local config file is missing: $path")
+            }
+            return;
+        }
+        elsif(! -e $v){
             $path = substr($path, 0, rindex($cnf_file,'/')) .'/'.$v;
         }else{
             $path = $v;
@@ -862,7 +872,7 @@ sub doDATAInstructions_{ my ($self,$e,$v,$t,$d)=@_;
 sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
 
      # We control from here the constances, as we need to unlock them if a previous parse was run.
-    unlock_hash(%$self);
+    unlock_hash(%$self); my $recursing = 0;
 
     if( not $content ){
         $cnf_file = $cnf_file -> {path} if ref($cnf_file) eq 'CNFGlobalFile';
@@ -870,9 +880,11 @@ sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
         or  CNFParserException->throw(error=>"Can't open $cnf_file -> $!",show_trace=>$self->{STACK_TRACE});
            read $fh, $content, -s $fh;
         close   $fh;
-        my @stat = stat($cnf_file);
-        $self->{CNF_STAT}    = \@stat;
-        $self->{CNF_CONTENT} = $CUR_SCRIPT = $cnf_file;
+        if(!$self->{CNF_CONTENT} eq 'script'){
+           my @stat = stat($cnf_file);
+              $self->{CNF_STAT}    = \@stat;
+              $self->{CNF_CONTENT} = $CUR_SCRIPT = $cnf_file;
+        }else{$recursing = 1}
     }else{
         my $type = Scalar::Util::reftype($content);
         if($type && $type eq 'ARRAY'){
@@ -1187,6 +1199,8 @@ sub parse {  my ($self, $cnf_file, $content, $del_keys) = @_;
     foreach my $k(@$del_keys){
         delete $self->{$k} if exists $self->{$k}
     }
+
+    return if $recursing;
     my $runProcessors = $self->{RUN_PROCESSORS} ? 1: 0;
     $self = lock_hash(%$self);#Make repository finally immutable.
     runPostParseProcessors($self) if $runProcessors;