]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
PluginBase implemented for modern Perl.
authorWill Budic <redacted>
Wed, 26 Mar 2025 02:56:02 +0000 (13:56 +1100)
committerWill Budic <redacted>
Wed, 26 Mar 2025 02:56:02 +0000 (13:56 +1100)
system/modules/DataProcessorPlugin.pm
system/modules/DataProcessorWorldCitiesPlugin.pm
system/modules/DatabaseCentralPlugin.pm
system/modules/GenericInstructionHandler.pm
system/modules/HTMLIndexProcessorPlugin.pm
system/modules/HTMLProcessorPlugin.pm
system/modules/MarkdownPlugin.pm
system/modules/PluginBase.pm [new file with mode: 0644]
tests/testHTMLConversion.pl

index d7ed32ed252f66d7919ec945ce0eb5424859cf7e..9fa05232fbbbc00b69403f6375985d4356e94658 100644 (file)
@@ -1,15 +1,6 @@
 package DataProcessorPlugin;
-
-use strict;
-use warnings; no warnings qw(experimental::signatures);
-
-use feature qw(signatures);
-use Scalar::Util qw(looks_like_number);
-use Clone qw(clone);
+use PluginBase;
 use Date::Manip;
-use Syntax::Keyword::Try;
-use Exception::Class ('PluginException');
-
 use constant VERSION => '1.0';
 
 sub new ($class, $plugin){
index a6c3caf55ac8b2262a5cf9ff496fd4ff4b9f2a19..52b1aa9e8acf70606b2742c9f417b8788721c49b 100644 (file)
@@ -1,11 +1,5 @@
 package DataProcessorWorldCitiesPlugin;
-
-use strict;
-use warnings; no warnings "once";
-
-use feature qw(signatures);
-use Scalar::Util qw(looks_like_number);
-
+use PluginBase; 
 # @Deprecated Plugin not needed anymore in script.
 sub new ($class,$plugin){
     return bless {}, $class
index 6e9b32babfc4d710670f42b44caf1d39c93d8c0b..b609cd61109794de7392a388658c75b331b091a1 100644 (file)
@@ -3,22 +3,15 @@
 # It also from script provided values to convert as data to basic CNF value types. Which can be meta directives.
 # This operate the premise of an column mapping functionality also, as a mapping via the CNF TREE instruction.
 # For speed direct here direct array referencing in a modal automation algorithmic approach is used.
-# It implements also atomic's heavily like CNFData table header and CNFMeta for varios possible operations.
+# It implements also atomic's heavily like CNFData table header and CNFMeta for various possible operations.
 ###
 package DatabaseCentralPlugin;
-
-use strict;
-use warnings; no warnings qw(experimental::signatures); no warnings 'once';
-
-use feature qw(signatures);
+use PluginBase;
+use Exception::Class ('DBCentralPluginException');
 
 use Time::Piece;
 use DBI;
-use Syntax::Keyword::Try;
-use Exception::Class ('DBCentralPluginException');
-use Clone qw(clone);
 use Date::Manip;
-use Scalar::Util qw(looks_like_number);
 
 require CNFDateTime;
 require CNFMeta;
index 20e1b20069aceac4e92e2ce81ba101c4af355553..504b48cf4699d7c42123f4cdf5d2693017a36c85 100644 (file)
@@ -1,8 +1,5 @@
 package GenericInstructionHandler;
-
-use strict;
-use warnings; no warnings qw(experimental::signatures);
-use feature qw(signatures);
+use PluginBase; 
 
 sub new {my ($class, $args) = @_; 
     bless $args, $class;
index 95969f7c6bfcbf40a5ee3c7d98f6403be96cefdc..147d749e9929a9d1748e264b081dd32943048e7c 100644 (file)
@@ -1,19 +1,12 @@
 package HTMLIndexProcessorPlugin;
-
-use strict;
-use warnings;
-no warnings qw(experimental::signatures);
-use Syntax::Keyword::Try;
+use PluginBase;
 use Exception::Class ('HTMLIndexProcessorPluginException');
-use feature qw(signatures);
-use Scalar::Util qw(looks_like_number);
-use Clone qw(clone);
+
 use CGI;
 use CGI::Session '-ip_match';
 
 use constant VERSION => '1.0';
 
-our $TAB = ' 'x4;
 
 sub new ($class, $plugin){
     my $settings;
@@ -32,7 +25,8 @@ sub convert ($self, $parser, $property) {
     my $cgi_action   = $cgi-> param('action');    
     my $cgi_doc      = $cgi-> param('doc'); 
     my $tree         = $parser-> anon($property);
-    die "Tree property '$property' is not available!" if(!$tree or ref($tree) ne 'CNFNode');    
+    die "Tree property '$property' is not available! Parser <pre> -&gt;\n".dumpParser($parser)."\n</pre>\n"
+     if(!$tree or ref($tree) ne 'CNFNode');    
 
 try{
 
@@ -104,10 +98,18 @@ try{
     }
     $parser->data()->{$property} = \$buffer;
  }catch($e){
-         HTMLIndexProcessorPluginException->throw(error=>$e ,show_trace=>1);
+    HTMLIndexProcessorPluginException->throw(error=>$e, show_trace=>1);
  }
 }
-#
+
+sub dumpParser($parser){
+    my $ret =  $parser ->writeOut();
+       $ret =~ s/</&gt;/g;
+       $ret =~ s/>/&lt;/g;
+       return $ret
+}
+
+###
 sub loadDocument($parser, $doc) {
     my $slurp = do {
                     open my $fh, '<:encoding(UTF-8)', $doc or HTMLIndexProcessorPluginException->throw("Document not avaliable: $doc");
index 062d80c83eb8b9b2969a97a34311d60f357a467e..e1354ef2efd512e654ded9c52e2971620285492f 100644 (file)
@@ -1,16 +1,10 @@
 ###
-# HTML converter Plugin from PerlCNF to HTML from TREE instucted properties.
+# HTML converter Plugin from PerlCNF to HTML from TREE instructed properties.
 # Processing of these is placed in the data parsers data.
 ###
 package HTMLProcessorPlugin;
-
-use strict;
-use warnings;
-use Syntax::Keyword::Try;
+use PluginBase; 
 use Exception::Class ('HTMLProcessorPluginException');
-use feature qw(signatures);
-use Scalar::Util qw(looks_like_number);
-use Clone qw(clone);
 
 use constant VERSION => '1.0';
 
index b32acc6c69319bd53513524cc40d538f74b807d5..f37c8e2a44500146990804443c6abd242cff2fd6 100644 (file)
@@ -4,19 +4,12 @@
 # Processing of these is placed in the data parsers data.
 #
 package MarkdownPlugin;
-
-use strict;
-use warnings;
-no warnings qw(experimental::signatures);
-use Syntax::Keyword::Try;
+use PluginBase; 
 use Exception::Class ('MarkdownPluginException');
-use feature qw(signatures);
-use Clone qw(clone);
 ##no critic ControlStructures::ProhibitMutatingListFunctions
 
 use constant VERSION => '1.1';
 
-our $TAB = ' 'x4;
 
 ###
 # Constances for CSS CNF tag parts. See end of this file for package internal provided defaults CSS.
@@ -55,12 +48,12 @@ try{
        $script = $item->{val};
        $escaped = $item->{ins} eq 'ESCAPED'
     }elsif($script !~ /\n/ and -e $script ){
-        my $file = $parser->anon($property);
-        $script = do {
+       my $file = $parser->anon($property);
+       $script = do {
         open my $fh, '<:encoding(UTF-8)', $script or MarkdownPluginException->throw("File not available: $script");
         local $/;
         <$fh>;
-        };
+       };
     }
     if($escaped){
        $script =~ s/\\</</gs;
@@ -217,7 +210,7 @@ try{
     my @titles;my $code = 0; my ($tag, $class);  my $pml_val = 0;  my ($bqte, $bqte_nested,$bqte_tag);
     $script =~ s/^\s*|\s*$//;
     foreach my $ln(split(/\n/,$script)){
-           $ln =~ s/\t/$TAB/gs; $lnc++;
+           $ln =~ s/\t/$PluginBase::TAB/gs; $lnc++;
         if($ln =~ /(.*) `{3}(\w*)\s*(.*)`{3}  (.*)/gx){
             my $pret = ""; $pret = $1 if $1;
             my $post = ""; $post = $4 if $4;
diff --git a/system/modules/PluginBase.pm b/system/modules/PluginBase.pm
new file mode 100644 (file)
index 0000000..7a051cf
--- /dev/null
@@ -0,0 +1,64 @@
+package PluginBase;
+use v5.36;
+use strict;
+use warnings; 
+use Syntax::Keyword::Try;
+use feature qw(signatures);
+use Scalar::Util qw(looks_like_number);
+use Clone qw(clone);
+use Module::Load;
+use Exception::Class ('PluginException');
+
+
+require Exporter;
+
+our $TAB = ' 'x4;
+our @ISA = qw(Exporter);
+our @EXPORT = qw($TAB);
+
+use Carp qw(confess);
+BEGIN {
+  $SIG{'__DIE__'} = sub { confess(@_) };  
+}
+
+
+sub import {
+
+    
+  feature->import(':5.36');
+  feature->import('signatures');
+  warnings->import;
+  warnings->unimport('once');
+  strict->import;  
+  Syntax::Keyword::Try->import;  
+  Module::Load->import;
+  Carp->import('confess');
+  Exception::Class->import('PluginException');
+
+
+  my $caller = caller(0);
+
+  do {
+    no strict 'refs';
+    *{"$caller\:\:clone"}  = *{"Clone\:\:clone"};
+    *{"$caller\:\:looks_like_number"}  = *{"Scalar\:\:Util\:\:looks_like_number"};
+  };
+
+
+}
+
+
+
+1;
+
+=begin copyright
+Programed by  : Will Budić
+EContactHash  : 990MWWLWM8C2MI8K (https://github.com/wbudic/EContactHash.md)
+Source        : git clone git://lifelog.hopto.org/PerlCNF
+              : https://github.com/wbudic/PerlCNF.git
+Documentation : Specifications_For_CNF_ReadMe.md
+    This source file is copied and usually placed in a local directory, outside of its repository project.
+    So it could not be the actual or current version, can vary or has been modified for what ever purpose in another project.
+    Please leave source of origin in this file for future references.
+Open Source Code License -> https://github.com/wbudic/PerlCNF/blob/master/ISC_License.md
+=cut copyright
\ No newline at end of file
index a97876b486451912cc39e874f8e0977e4e94c249..f9d92bcb61b09a9fb7d870f4cac37d5197bee88f 100644 (file)
@@ -54,6 +54,8 @@ use Syntax::Keyword::Try; try {
 ]row]
 >>));
 
+
+
     my $plugin = HTMLProcessorPlugin -> new({Language=>'English',DateFormat=>'AU'}) -> convert($parser, 'test1');
     my $html = $parser->data()->{'test1'};
     my $tree = $parser->anon('test1');