From 9c87942b5376b3828c560d7c1198621efd31cdb7 Mon Sep 17 00:00:00 2001 From: Will Budic Date: Sun, 9 Nov 2025 08:16:41 +1100 Subject: [PATCH] Made library specific required that to be _import_into_this_package static function to be used. --- system/modules/CNFMeta.pm | 35 ++++++++++++++++--------- system/modules/CNFNode.pm | 2 +- system/modules/CNFParser.pm | 17 ++++++------ system/modules/DatabaseCentralPlugin.pm | 8 +++--- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/system/modules/CNFMeta.pm b/system/modules/CNFMeta.pm index 1b699d8..4b4efcd 100644 --- a/system/modules/CNFMeta.pm +++ b/system/modules/CNFMeta.pm @@ -9,9 +9,14 @@ # package CNFMeta; -use strict; -use warnings; no warnings qw(experimental::signatures); -use constant VERSION => "2.0"; +use strict; use warnings; no warnings qw(experimental::signatures); +use constant { + VERSION => "2.0", #Version of CNFMeta itself is this, not exported, access with CNFMeta::VERSION. + DELIMITER => qr/(?:,\s*)|\s+/, # match a comma or whitespace + WILDCARD => qr/[\*\?]/, # wildcards: *.html foo??.txt + PRIORITY => qr/(\s*\_+PRIORITY\_(\d+)\_+\s*)/o, # Priority order no. for instructions. + ANN => '__ANN__' # ANONYMOUS tag name assigned where name is not given or tagged. +}; ### # Returns the regular expression for any of the meta constances. @@ -25,13 +30,6 @@ sub _meta { } # -### -# Priority order no. for instructions. -use constant PRIORITY => qr/(\s*\_+PRIORITY\_(\d+)\_+\s*)/o; -### -# ANONYMOUS tag name assigned where name is not given or tagged. -use constant ANN => '__ANN__'; - # We lock lookup hashes, in case they change in this package, to protect them, as READONLY. # Will rise exceptions in outside older code not being updated to use new keys, or trying to modify them. use Hash::Util qw(lock_hash); @@ -53,7 +51,14 @@ my $cnt =0; foreach(qw{BOOL INT CNFID NUMBER DATE TEXT}){$CNF_DATA_TYPES{$_}=++$ # Global setting for SQL TEXT to CNF _TEXT_ specified data type range. Programmatically changeable. our $SQL_CNF_VAR_LENGTH = 2024; -sub import { +### +# All packages here are Perl required libraries not is in use CPAN's Exporter module. +# When requiring CNFMeta this static method should be called to get its methods and constances() +# imported into name space of your new package. +# Caveat to such implementation is that on initial compile time syntax errors can not be apparent. +# Advantage is that package name spaces are less convoluted. +### +sub _import_into_this_package { my $caller = caller; no strict "refs"; { # TREE instruction meta. @@ -72,13 +77,17 @@ sub import { # resulting in unintended placings. *{"${caller}::meta_node_in_shortife"} = sub {return _meta("IN_SHORTIFE")}; # Execute via system shell. - *{"${caller}::meta"} = \&_meta; - *{"${caller}::SHELL"} = sub {return _meta("SHELL")}; + *{"${caller}::meta"} = \&_meta; + *{"${caller}::SHELL"} = sub {return _meta("SHELL")}; # Returns the regular expression for any of the meta constances. + *{"${caller}::ANN"} = \&ANN; + *{"${caller}::DELIMITER"} = \&DELIMITER; + *{"${caller}::WILDCARD"} = \&WILDCARD; } return 1; } + ### # Data base conversion types supported from the CNF side. ### diff --git a/system/modules/CNFNode.pm b/system/modules/CNFNode.pm index b6fbf9a..43573be 100644 --- a/system/modules/CNFNode.pm +++ b/system/modules/CNFNode.pm @@ -7,7 +7,7 @@ use warnings; use Syntax::Keyword::Try; use Carp qw(cluck); -require CNFMeta; CNFMeta::import(); +require CNFMeta; CNFMeta::_import_into_this_package(); sub new { my ($class, $attrs) = @_; diff --git a/system/modules/CNFParser.pm b/system/modules/CNFParser.pm index c5c2520..353b0a3 100644 --- a/system/modules/CNFParser.pm +++ b/system/modules/CNFParser.pm @@ -13,7 +13,7 @@ use IO::Handle qw(flush); use IO::Compress::Xz qw($XzError); use IO::Uncompress::UnXz qw($UnXzError); -require CNFMeta; CNFMeta::import(); +require CNFMeta; CNFMeta::_import_into_this_package(); require CNFNode; require CNFDateTime; @@ -123,15 +123,14 @@ sub new { my ($class, $path, $attrs, $del_keys, $self) = @_; sub blank{ return new(shift,undef,@_) } - -sub import { +## @see CNFMeta for explanation. +sub _import_into_this_package { my $caller = caller; no strict "refs"; { *{"${caller}::configDumpENV"} = \&dumpENV; *{"${caller}::anon"} = \&anon; *{"${caller}::SQL"} = \&SQL; - *{"${caller}::isCNFTrue"} = \&_isTrue; - *{"${caller}::now"} = \&now; + *{"${caller}::isCNFTrue"} = \&_isTrue; } return 1; } @@ -532,7 +531,7 @@ sub doInstruction { my ($self,$e,$t,$v,$is_tagged) = @_; }elsif($t eq 'TREE'){ my $tree = 0; if( !$is_tagged){ - $e = CNFMeta::ANN(); + $e = ANN(); } if( $v =~ s/($meta_has_priority)/""/ei ){ $priority = 1; @@ -561,7 +560,7 @@ sub doInstruction { my ($self,$e,$t,$v,$is_tagged) = @_; my $ret; if (!$v){ $v = $e; - $e = CNFMeta::ANN(); + $e = ANN(); } if( $v =~ s/($meta_has_priority)/""/ei ){ $priority = 1; @@ -1192,7 +1191,7 @@ sub parse { my ($self, $cnf_file, $content, $del_keys) = @_; my $priority = $struct-> {'^'}; if($type eq 'CNFNode' && $priority > 0 && $priority < 5){ $struct->validate() if $self->{ENABLE_WARNINGS}; - if($struct->name() eq CNFMeta::ANN()){ + if($struct->name() eq ANN()){ my $anode = $struct->process($self, $struct->script()); foreach my $node($$anode->nodes()){ $anechoic ->{$node->name()} = \$node; @@ -1220,7 +1219,7 @@ sub parse { my ($self, $cnf_file, $content, $del_keys) = @_; my $type = ref($struct); if($type eq 'CNFNode'){ $struct->validate() if $self->{ENABLE_WARNINGS}; - if($struct->name() eq CNFMeta::ANN()){ + if($struct->name() eq ANN()){ my $anode = $struct->process($self, $struct->script()); foreach my $node($$anode->nodes()){ $anechoic ->{$node->name()} = \$node; diff --git a/system/modules/DatabaseCentralPlugin.pm b/system/modules/DatabaseCentralPlugin.pm index 6dd6605..89c0256 100644 --- a/system/modules/DatabaseCentralPlugin.pm +++ b/system/modules/DatabaseCentralPlugin.pm @@ -13,7 +13,7 @@ use Time::Piece; use DBI; use Date::Manip; -require CNFDateTime; require CNFMeta; require CNFSQL; +require CNFDateTime; require CNFMeta; require CNFSQL; CNFParser::_import_into_this_package(); use constant VERSION => '1.1'; my ($IS_SQLITE,$DSN,$SUPPRESS_DATA_LOG)=(0,(),0); @@ -48,9 +48,9 @@ sub centralDBConnect($self){ die "DB not set!" if !$dbname; $IS_SQLITE = $datasource =~ /DBI:SQLite/i; $dbname .= '.db' if $IS_SQLITE && $dbname !~ /.db$/; $DSN = $datasource .'dbname='.$dbname; - $SUPPRESS_DATA_LOG = CNFParser::_isTrue($suppress_data_log); - $is_auto_commit = CNFParser::_isTrue($is_auto_commit); - $is_raise_error = CNFParser::_isTrue($is_raise_error); + $SUPPRESS_DATA_LOG = isCNFTrue($suppress_data_log); + $is_auto_commit = isCNFTrue($is_auto_commit); + $is_raise_error = isCNFTrue($is_raise_error); $self->{DSN} = $DSN; $self->{db_name} = $dbname; $self->{is_sqlite} = $IS_SQLITE; -- 2.34.1