##no critic qw(Subroutines::RequireFinalReturn)
##no critic Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions
-use constant VERSION => '3.2';
+use constant VERSION => '3.2';
+use constant APPSET => 'APP_SETTINGS';
our @files;
our %lists;
our %properties;
if($ref eq 'ARRAY'){
return @{$ret}
}elsif($ref eq 'PropertyValueStyle'){
- return ${$ret->{plugin}} if $ret->{instructor} eq 'APP_SETTINGS';
+ return ${$ret->{plugin}} if $ret->{instructor} eq APPSET;
return $ret;
}
else{
elsif($t eq 'MACRO'){
$instructs{$e}=$v;
}
- elsif($t eq 'APP_SETTINGS'){
- $self->instructPlugin(InstructedDataItem -> new($e, 'APP_SETTINGS', $v));
+ elsif($t eq 'APPSET'){
+ $self->instructPlugin(InstructedDataItem -> new($e, APPSET, $v));
}
elsif(exists $instructors{$t}){
if(not $instructors{$t}->instruct($e, $v) && $self->{STRICT}){
my $t = $1;
my $v = $2;
if(isReservedWord($self, $t)){
+ my $isAppSts = ($t eq APPSET);
my $isVar = ($t eq 'VARIABLE' || $t eq 'VAR');
- if($t eq 'CONST' or $isVar){ #constant multiple properties.
- foreach my $line (split '\n', $v) {
- my $isMETAConst = $line =~ s/$meta_const//s;
+ if($t eq 'CONST' or $isVar or $isAppSts){ #multiple values property.
+ my %app_sts;
+ foreach my $line(split '\n', $v) {
+ my $isMETAConst = $line =~ s/$meta_const//se;
$line =~ s/^\s+|\s+$//; # strip unwanted spaces
$line =~ s/\s*>$//;
$line =~ m/([\$\w]*)(\s*=\s*)(.*)/g;
my $name = $1;
$line = $3; $line =~ s/^\s*(['"])(.*)\g{1}$/$2/ if $line;#strip quotes
if(defined $name){
- if($isVar && not $isMETAConst){
- $anons ->{$name} = $line if $line
+ if($isAppSts){
+ $app_sts{$name} = $line if $line;
+ }elsif($isVar && not $isMETAConst){
+ $anons -> {$name} = $line if $line
}else{
$name =~ s/^\$// if $isMETAConst;
# It is NOT allowed to overwrite a constant, so check an issue warning.
- if($line and not $self->{$name}){
+ if(not exists($self->{$name})){
$self->{$name} = $line;
}else{ my
$w = "Skipping and keeping a previously set constance of -> [$name] in ". $self->{CNF_CONTENT}." the new value ";
}
}
}
+ if($isAppSts){
+ $properties{CNFParser::APPSET} = \%app_sts
+ }
}else{
doInstruction($self,$v,$t,undef);
}
my $pck = $plugin->{package};
my $prp = $plugin->{property};
my $sub = $plugin->{subroutine};
- if($instructor eq 'APP_SETTINGS'){
+ if($instructor eq APPSET){
$pck = 'ClassicAppSettings' if ! $pck;
## no critic (RequireBarewordIncludes)
require "$pck.pm";
my $logfile = $log{file};
my $tail_cnt = $log{tail};
if($logfile){
- open (my $fh, ">>", $logfile) or die $!;
+ open (my $fh, ">>", $logfile) or CNFParserException->throw(error=>"Error With accessing logfile: $logfile -> $!");
print $fh $time . " - " . $message ."\n";
close $fh;
if($tail_cnt>0 && !$LOG_TRIM_SUB){
return bless $settings, $class
}
-my %hdr;
+
###
# Process config data to contain expected fields.
###
sub process ($self, $parser, $property) {
- my @data = @{$parser->data()->{$property}};
+
+ my $table = $parser->data()->{$property};
+ if(!$table){
+ $parser->error("RSSFeedsPlugin\@Error Table property not found -> $property"); return
+ }
my $cgi = $parser->const('CGI');
$self->{date} = now();
+ my $ptr = $$table->{header};
+ my $ref = ref($ptr);
+ if($ref eq 'REF'){
+ $ptr = $$ptr;
+ }
+ my @header = @$ptr;
+ my @data = CNFMeta::_deRefArray($$table->{data});
for my $idx (0 .. $#data){
my @col = @{$data[$idx]};
- if($idx>0){
- $col[0] = $idx+1;
- $col[@col] = $self-> {date} -> toTimestamp();
+ if($idx==0){
+ $col[4] = 'last_updated';
+ if(@header){
+ my @lbls = CNFMeta::_deRefArray($header[0]);
+ my @spec = CNFMeta::_deRefArray($header[3]);
+ $lbls[4] = $col[4];
+ $spec[4] = $CNFMeta::CNF_DATA_TYPES{DATE};
+ $$table->{header} = \[\@lbls,$header[1],$header[2],\@spec];
+ }
}else{
- $col[@col] = 'last_updated';
+ $col[0] = $idx+1;
+ $col[4] = $self-> {date} -> toTimestamp();
}
$data[$idx]=\@col;
}
if($cgi&&$cgi->param('action') eq 'list'){
- my $page = _css().'<div class="feed"><h2>List Of Feeds</h2><ol>';
- for my $idx (0 .. $#data){
+ my $page = '<div class="feed"><h2>List Of Feeds</h2><ol>';
+ for my $idx (1 .. $#data){
my @col = @{$data[$idx]};
-
- if($idx==0){
- for my $i(0..$#col){ # Get the matching table column index names as scripted.
- $hdr{$col[$i]} = $i
- }
- }else{
- $page .= qq|<li><span class="feeds_list_span">
- <a onclick="return fetchFeed('$col[$hdr{Name}]')" style="cursor: pointer;"> <b>$col[$hdr{Name}]</b> </a></span>
- [ $col[$hdr{last_updated}] ]<dt style="padding:10px;">$col[$hdr{Description}]</dt></li>\n|;
- }
+ $page .= qq|<li><span style="border: 1px solid black; padding: 5px; padding-bottom: 0px;">
+ <a onclick="return fetchFeed('$col[1]')" style="cursor: pointer;"> <b>$col[1]</b> </a></span>
+ [ $col[4] ]<dt style="padding:10px;">$col[3]</dt></li>\n|;
}
$page .= '</ol></div>';
$parser->data()->{PAGE} = \$page
}else{
$parser->addPostParseProcessor($self,'collectFeeds');
}
- $parser->data()->{$property} = \@data
-}
-
-sub _css{
-<<__CSS;
-<style>
-.feeds_list_span{
- border: 1px solid black; padding: 5px; padding-bottom: 0px;
-}
-.feeds_list_span:hover{
- border-color:red;
- background:#94cde7;;
-}
-</style>
-__CSS
+ $parser->data()->{$property} = \{name=>$property,header=>$$table->{header},auto=>0,data=>\@data}
}
sub collectFeeds($self, $parser) {
my $property = $self->{property};
- my @data = @{$parser->data()->{$property}};
- my $cgi = $parser->const('CGI');
+
+ my $table = $parser->data()->{$property};
+ my $ptr = $$table->{header};
+ my $ref = ref($ptr);
+ if($ref eq 'REF'){
+ $ptr = $$ptr;
+ }
my $page;
+ my @header = @$ptr;
+ my @data = @{$$table->{data}};
+ my $cgi = $parser->const('CGI');
my $feed = $cgi->param('feed') if $cgi;
- $parser->log("Feed request:$feed");
+ my @lbls = CNFMeta::_deRefArray($header[0]);
+ my %hdr;
+ for(my $i=0;$i<@lbls;$i++){ #<- Column names are set here, if names in script are changed, They must be changed bellow.
+ $hdr{$lbls[$i]} = $i
+ }
+ $parser->log("Feed request:$feed") if$feed;
for my $idx (0 .. $#data){
- my @col = @{$data[$idx]};
- if($idx==0){
- for my $i(0..$#col){ # Get the matching table column index names as scripted.
- $hdr{$col[$i]} = $i
- }
- }else{
- my $name = $col[$hdr{Name}]; #<- Now use the column names as coded, if names in script are changed, you must change here.
+ my @col = @{$data[$idx]};
+ my $name = $col[$hdr{Name}];
next if($feed && $feed ne $name);
- my $tree = fetchFeed($self, $name, $col[$hdr{URL}], $col[$hdr{Expires}], $col[$hdr{Description}]);
+ my $tree = fetchFeed($self, $name, $col[$hdr{URL}], $col[$hdr{Description}]);
$parser->log("Fetched feed:".$name);
if($tree && ref($$tree) eq 'CNFNode'){
if(not isCNFTrue($self->{CNF_TREE_LOADED}) && isCNFTrue($self->{CNF_TREE_STORE})){
}else{
$parser-> warn("Feed '$name' bailed to return a CNFNode tree.")
}
- }
}
$parser->data()->{PAGE} = \$page if $page;
}