From: Will Budic Date: Tue, 23 Sep 2025 12:46:03 +0000 (+1000) Subject: new. feature conventional script name loading of with FILE command with $0. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=5ed59b714430ae1cfc452ed9c136c1ecd54fe134;p=PerlCNF.git new. feature conventional script name loading of with FILE command with $0. --- diff --git a/system/modules/CNFParser.pm b/system/modules/CNFParser.pm index 3ef1efd..a60beff 100644 --- a/system/modules/CNFParser.pm +++ b/system/modules/CNFParser.pm @@ -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;