[LON-CAPA-cvs] cvs: loncom /interface lonhtmlcommon.pm

raeburn raeburn@source.lon-capa.org
Mon, 03 Jan 2011 13:10:12 -0000


raeburn		Mon Jan  3 13:10:12 2011 EDT

  Modified files:              
    /loncom/interface	lonhtmlcommon.pm 
  Log:
  - defined(%hash) is deprecated in perl 5.12.
  - sanity check for array refs.
  - cde style for &echo_form_input().
  
  
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.284 loncom/interface/lonhtmlcommon.pm:1.285
--- loncom/interface/lonhtmlcommon.pm:1.284	Mon Oct  4 14:34:46 2010
+++ loncom/interface/lonhtmlcommon.pm	Mon Jan  3 13:10:12 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.284 2010/10/04 14:34:46 www Exp $
+# $Id: lonhtmlcommon.pm,v 1.285 2011/01/03 13:10:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1603,7 +1603,7 @@
     sub add_breadcrumb_tool {
         my ($category, @html) = @_;
         return unless @html;
-        if (!defined(%tools)) { 
+        if (!keys(%tools)) { 
             %tools = ( navigation => [], tools => [], advtools => []);
         }
 
@@ -1643,7 +1643,7 @@
 #TODO might split this in separate functions for each category
     sub render_tools {
         my ($breadcrumbs) = @_;
-        return unless defined %tools;
+        return unless (keys(%tools));
 
         my $navigation = list_from_array($tools{navigation}, 
                    { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
@@ -2105,30 +2105,30 @@
         if ($key =~ /^form\.(.+)$/) {
             my $name = $1;
             my $match = 0;
-            if ((!@{$excluded}) || (!grep/^$name$/,@{$excluded})) {
-                if (defined($regexps)) {
-                    if (@{$regexps} > 0) {
-                        foreach my $regexp (@{$regexps}) {
-                            if ($name =~ /\Q$regexp\E/) {
-                                $match = 1;
-                                last;
-                            }
+            if (ref($excluded) eq 'ARRAY') {    
+                next if (grep(/^\Q$name\E$/,@{$excluded}));
+            }
+            if (ref($regexps) eq 'ARRAY') {
+                if (@{$regexps} > 0) {
+                    foreach my $regexp (@{$regexps}) {
+                        if ($name =~ /$regexp/) {
+                            $match = 1;
+                            last;
                         }
                     }
                 }
-                if (!$match) {
-                    if (ref($env{$key})) {
-                        foreach my $value (@{$env{$key}}) {
-                            $value = &HTML::Entities::encode($value,'<>&"');
-                            $output .= '<input type="hidden" name="'.$name.
-                                             '" value="'.$value.'" />'."\n";
-                        }
-                    } else {
-                        my $value = &HTML::Entities::encode($env{$key},'<>&"');
-                        $output .= '<input type="hidden" name="'.$name.
-                                             '" value="'.$value.'" />'."\n";
-                    }
+            }
+            next if ($match);
+            if (ref($env{$key}) eq 'ARRAY') {
+                foreach my $value (@{$env{$key}}) {
+                    $value = &HTML::Entities::encode($value,'<>&"');
+                    $output .= '<input type="hidden" name="'.$name.
+                               '" value="'.$value.'" />'."\n";
                 }
+            } else {
+                my $value = &HTML::Entities::encode($env{$key},'<>&"');
+                $output .= '<input type="hidden" name="'.$name.
+                           '" value="'.$value.'" />'."\n";
             }
         }
     }
@@ -2429,6 +2429,7 @@
 # \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
 sub list_from_array {
     my ($items, $args) = @_;
+    return unless (ref($items) eq 'ARRAY');
     return unless scalar @$items;
     my ($ul, $li) = inittags( qw(ul li) );
     my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
@@ -2641,6 +2642,7 @@
 
 sub funclist_from_array {
     my ($items, $args) = @_;
+    return unless(ref($items) eq 'ARRAY');
     $args->{legend} ||= mt('Functions');
     return list_from_array( [$args->{legend}, @$items], 
                { listattr => {class => 'LC_funclist'} });