From: Nicolas Boisselier Date: Wed, 22 Nov 2023 21:05:07 +0000 (+0100) Subject: Created to share textOutput between scripts meteo and nico-app X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=418b7cdade4d16740c460388494e82abc7f410f0;p=nb.git Created to share textOutput between scripts meteo and nico-app --- diff --git a/lib/perl/NB/CGI.pm b/lib/perl/NB/CGI.pm new file mode 100644 index 00000000..d179c660 --- /dev/null +++ b/lib/perl/NB/CGI.pm @@ -0,0 +1,79 @@ +package NB::CGI; +# NB 22.11.23: TODO +use strict; +use parent qw/CGI/; + +sub textOutput {{ + no warnings 'redefine'; + no warnings 'once'; + #return unless $Opt{html}; + + *CGI::_tag_func = sub { + my $tagname = shift; + my ($q,$a,@rest) = CGI::self_or_default(@_); + + #return "$a\t" if ref($a) eq '' and $a; # LABEL + #warn $tagname; return ''; + + my($attr) = ''; + if (ref($a) && ref($a) eq 'HASH') { + my(@attr) = CGI::make_attributes($a,$q->{'escape'}); + $attr = " @attr" if @attr; + } else { + unshift @rest,$a if defined $a; + } + + $tagname = lc( $tagname ); + my @result = (ref($rest[0]) eq 'ARRAY') ? @{$rest[0]} : "@rest"; + + if (0) + { + } + # H. + elsif ($tagname =~ /^h(\d+)$/) + { + @result = map {"$_\n";} @result; + } + # TH + elsif ($tagname eq 'th') + { + #@result = map { &str_center($_)."\n" } @result; + @result = map {$_ ? "$_\n" : '';} @result; + } + # TD + elsif ($tagname =~ /^(start_)?td$/) + { + #warn $tagname if ($tagname =~ /^(start_)?td$/); + @result = map {"|$_";} @result; + } + + @result = grep {$_ ne ' '} @result; + return "@result"; + }; + *CGI::start_TR = sub { return "" }; + *CGI::end_TR = sub { return "|\n" }; + *CGI::button = sub { '' }; + *CGI::checkbox = sub { '' }; + *CGI::start_html = sub { '' }; + *CGI::end_html = sub { '' }; + *CGI::popup_menu = sub { + my($self,@p) = CGI::self_or_default(@_); + use Data::Dumper; + #die Dumper(\@p); + my(@values); + #for (@p) + while (@p) + { + $_ = shift @p; + #warn ">>>$_"; next; + next unless $_ eq '-labels'; + #die 'zaza'; + my $labels = shift @p; + @values = map {$labels->{$_}."\t".$_} keys %$labels; + last; + } + return map {"$_\n"} @values; + + }; +}} +1;