CGI support #2736
Replies: 5 comments 3 replies
-
There are several way we could approach this. Could you please give me few samples of these dynamic methods (preferably from different packages, I'll take a look). |
Beta Was this translation helpful? Give feedback.
-
If we take the instance of table cell generation, the CGI library provided HTML generation via the "td" subroutine. sub _all_html_tags {
return qw/
a abbr acronym address applet Area
b base basefont bdo big blink blockquote body br
caption center cite code col colgroup
dd del dfn div dl dt
em embed
fieldset font fontsize frame frameset
h1 h2 h3 h4 h5 h6 head hr html
i iframe ilayer img input ins
kbd
label layer legend li Link
Map menu meta
nextid nobr noframes noscript
object ol option
p Param pre
Q
samp script Select small span
strike strong style Sub sup
table tbody td tfoot th thead title Tr TR tt
u ul
var
/
}
foreach my $tag ( _all_html_tags() ) {
*$tag = sub { return _tag_func($tag,@_); };
# start_html and end_html already exist as custom functions
next if ($tag eq 'html');
foreach my $start_end ( qw/ start end / ) {
my $start_end_function = "${start_end}_${tag}";
*$start_end_function = sub { return _tag_func($start_end_function,@_); };
}
}
sub _tag_func {
my $tagname = shift;
my ($q,$a,@rest) = self_or_default(@_);
my($attr) = '';
if (ref($a) && ref($a) eq 'HASH') {
my(@attr) = make_attributes($a,$q->{'escape'});
$attr = " @attr" if @attr;
} else {
unshift @rest,$a if defined $a;
}
$tagname = lc( $tagname );
if ($tagname=~/start_(\w+)/i) {
return "<$1$attr>";
} elsif ($tagname=~/end_(\w+)/i) {
return "</$1>";
} else {
return $XHTML ? "<$tagname$attr />" : "<$tagname$attr>" unless @rest;
my($tag,$untag) = ("<$tagname$attr>","</$tagname>");
my @result = map { "$tag$_$untag" }
(ref($rest[0]) eq 'ARRAY') ? @{$rest[0]} : "@rest";
return "@result";
}
} We can then use A "fuller" dive into what CGI.pm exports is located at line 227: %EXPORT_TAGS = (
':html2' => [ 'h1' .. 'h6', qw/
p br hr ol ul li dl dt dd menu code var strong em
tt u i b blockquote pre img a address cite samp dfn html head
base body Link nextid title meta kbd start_html end_html
input Select option comment charset escapeHTML
/ ],
':html3' => [ qw/
div table caption th td TR Tr sup Sub strike applet Param nobr
embed basefont style span layer ilayer font frameset frame script small big Area Map
/ ],
':html4' => [ qw/
abbr acronym bdo col colgroup del fieldset iframe
ins label legend noframes noscript object optgroup Q
thead tbody tfoot
/ ],
':form' => [ qw/
textfield textarea filefield password_field hidden checkbox checkbox_group
submit reset defaults radio_group popup_menu button autoEscape
scrolling_list image_button start_form end_form
start_multipart_form end_multipart_form isindex tmpFileName uploadInfo URL_ENCODED MULTIPART
/ ],
':cgi' => [ qw/
param multi_param upload path_info path_translated request_uri url self_url script_name
cookie Dump raw_cookie request_method query_string Accept user_agent remote_host content_type
remote_addr referer server_name server_software server_port server_protocol virtual_port
virtual_host remote_ident auth_type http append save_parameters restore_parameters param_fetch
remote_user user_name header redirect import_names put Delete Delete_all url_param cgi_error env_query_string
/ ],
':netscape' => [qw/blink fontsize center/],
':ssl' => [qw/https/],
':cgi-lib' => [qw/ReadParse PrintHeader HtmlTop HtmlBot SplitParam Vars/],
':push' => [qw/multipart_init multipart_start multipart_end multipart_final/],
# bulk export/import
':html' => [qw/:html2 :html3 :html4 :netscape/],
':standard' => [qw/:html2 :html3 :html4 :form :cgi :ssl/],
':all' => [qw/:html2 :html3 :html4 :netscape :form :cgi :ssl :push/]
); In many cases our various applications' code will Thanks for taking a look at this, and if anything I've said needs expanding or clarification please let me know. I would love to have this (and the subs!) "resolved". |
Beta Was this translation helpful? Give feedback.
-
Thanks for the insights. Looking into it. |
Beta Was this translation helpful? Give feedback.
-
You may try artifacts from https://github.com/Camelcade/Perl5-IDEA/actions/runs/5630912445 should work just fine (see |
Beta Was this translation helpful? Give feedback.
-
I see the "Support" button on the project home on GitHub, but it doesn't have any funding sources options listed. Can you add a FUNDING file in the project and/or let me know where and how I can get some money your way? This change is going to change everything for me and I would really like to pay you for your time. Thanks again. |
Beta Was this translation helpful? Give feedback.
-
Would it be possible for you to implement a plugin for CGI as you have for e.g. Mojolicious or HTML::Mason? My problem is the numerous warnings thrown due to our legacy code's usage of the HTML generation functions in the CGI library. (I know, I know...) Mostly it's "Unable to find sub definition, declaration, constant definition or typeglob aliasing", as it seems that instead of directly exporting those functions, the CGI library generates them and then exports them in a non-typical way.
This would directly benefit my workflow and I'd be willing to donate money (USD) to the effort. If this is not possible at this time, is there a workaround for this that you can think of? A similar discussion may have been #2416 - however I don't quite follow the potential solution you presented there.
Thank you for all of your hard work!
Beta Was this translation helpful? Give feedback.
All reactions