]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
Made library specific required that to be _import_into_this_package static function...
authorWill Budic <redacted>
Sat, 8 Nov 2025 21:16:41 +0000 (08:16 +1100)
committerWill Budic <redacted>
Sat, 8 Nov 2025 21:16:41 +0000 (08:16 +1100)
system/modules/CNFMeta.pm
system/modules/CNFNode.pm
system/modules/CNFParser.pm
system/modules/DatabaseCentralPlugin.pm

index 1b699d88ada4d7fb45de50bc128347a580fe6ca8..4b4efcdc83110bef443f5dbd8e653757e7ccda22 100644 (file)
@@ -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.
 ###
index b6fbf9ac74caba521a7e72945d30bbb733860558..43573be55902c6d26fb78c61b88007ec54ff8283 100644 (file)
@@ -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) = @_;
index c5c25203b180cf4c2c431cd120438fa6b7cc83e1..353b0a350943762c540d49f4718cd2c52bd4c39c 100644 (file)
@@ -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;
index 6dd6605a0aa170ab3968d2c01f033161fd0daf3b..89c0256ea56b0dc101d82c5330075a0aca6a75b2 100644 (file)
@@ -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;