Skip Menu |

This queue is for tickets about the Javascript-Menu CPAN distribution.

Report information
The Basics
Id: 16025
Status: new
Priority: 0/
Queue: Javascript-Menu

People
Owner: Nobody in particular
Requestors: m.romani [...] spinsoft.it
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Patch to avoid using CGI.pm
I had problems running Javascript::Menu under Win32/Apache-2.0.54/mod_perl-2.0.1/Perl-5.8.7 because of CGI.pm, so I removed its use from the module. I substituted the calls to CGI.pm's routines with standard string-concat operations. HTH someone...
--- Menu.pm.orig 2005-11-22 08:54:01.976071418 +0100 +++ Menu.pm 2005-11-21 23:37:33.000000000 +0100 @@ -2,7 +2,6 @@ use strict; -use CGI; use Tree::Numbered; use constant DEFAULT_STYLES => {caption => 'caption', @@ -12,9 +11,6 @@ our $VERSION = '2.02'; our @ISA = qw(Tree::Numbered); -# package stuff: -my $cgi = CGI->new; # Just for HTML shortcuts. - # A default action generator. See the args passed to it: my $default_action = sub { my $self = shift; @@ -149,13 +145,9 @@ $action =~ s/([^;])\s*$/$1;/; my @html; # return value. - push @html, $cgi->div({-class => $styles->{caption}, - -id => "caption_$unique", - -onMouseOver => "showMenu(1, 0, 'main_$unique', " . - "this, 'main_$unique')", - -onMouseOut => "outOfMenu()", - -onClick => "${action}hideMenus(0)" - }, $caption); + push(@html, + "<div class=\"" . $styles->{caption} . "\" id=\"caption_$unique\" onMouseOver=\"showMenu(1,0,'main_$unique',this,'main_$unique')\" onMouseOut=\"outOfMenu()\" onClick=\"${action}hideMenus(0)\">$caption</div>" + ); $self->buildTable(1, 0, $unique, \@html, $args{no_ie}, %$styles); return @html if (wantarray); @@ -190,7 +182,8 @@ $name = "s_${serial}_$unique" } - my $htmlstr = $cgi->start_table({-class => $style, -id => $name}); + #my $htmlstr = $cgi->start_table({-class => $style, -id => $name}); + my $htmlstr = "<table class=\"$style\" id=\"$name\">"; my $next_level = $level + 1; $self->savePlace; @@ -207,17 +200,17 @@ $onMouse =~ s/~1/$next_level/e; $item->buildTable(0, $next_level, $unique, $html, $no_ie, %styles); - } else {$onMouse = "stopTimer();hideMenus($next_level);";} + } else { + $onMouse = "stopTimer();hideMenus($next_level);"; + } my $caption = $item->getFullCap($no_ie); $onClick =~ s/([^;])\s*$/$1;/; - $htmlstr .= $cgi->Tr($cgi->td({-onMouseOver => $onMouse, - -onClick => "${onClick}hideMenus(0)", - -onMouseOut => 'outOfMenu()'}, - $caption )); + $htmlstr .= "<tr><td onMouseOver=\"$onMouse\" onClick=\"${onClick}hideMenus(0)\" onMouseOut=\"outOfMenu()\">$caption</td></tr>"; } + $self->restorePlace; - $htmlstr .= $cgi->end_table; + $htmlstr .= "</table>"; push @$html, $htmlstr; }
The problems with inline HTML are too big to use this as is. For one, it is way too difficult to edit. Another problem is with quoting and escaping. There's more. To achieve your goal in a way that can be included into the module, I can think of two ways: 1. use a templating module, preferably HTML::Template, to create the HTML, and let the module just fill in the values - I've been planning this for a long time, but don't have time to code it. 2. create a set of matching functions, perhaps in a mock CGI object, and use either CGI or this - let's call it mock_CGI, depending on an argument for import: use Javascript::Menu qw(:noCGI); I suppose most users will still prefer CGI.pm, since it's battle tested and trustworthy, so it would be good if these functions could be eval()ed on demand: eval <DATA> if $noCGI; or something like that, I don't remmember the exact technique.
[YOSEFM - Tue Nov 22 17:19:46 2005]: Show quoted text
> The problems with inline HTML are too big to use this as is. For one, it > is way too difficult to edit. Another problem is with quoting and > escaping. There's more. > > To achieve your goal in a way that can be included into the module, I > can think of two ways: > > 1. use a templating module, preferably HTML::Template, to create the > HTML, and let the module just fill in the values - I've been planning > this for a long time, but don't have time to code it. > > 2. create a set of matching functions, perhaps in a mock CGI object, and > use either CGI or this - let's call it mock_CGI, depending on an > argument for import: > > use Javascript::Menu qw(:noCGI); > > I suppose most users will still prefer CGI.pm, since it's battle tested > and trustworthy, so it would be good if these functions could be > eval()ed on demand: > > eval <DATA> if $noCGI; > > or something like that, I don't remmember the exact technique.
I agree with you that it's better to use 'standard ways' to generate HTML than code it by hand. It's a pity that CGI still doesn't play nice with apache2/mod_perl2 (at least on my WinXP-SP2/AcrivePerl 813 laptop). Mine was just a quick hack to solve this issue since I didn't have the time to see if I could fix CGI.pm. As for your proposals, I think 1) is a bit overkill since we're talking about a bunch of html tags. I like 2) but I currently don't have time to code it... I'll keep it in my todo file though ;-)