Diff for /loncom/interface/lonhelper.pm between versions 1.10 and 1.11

version 1.10, 2003/04/11 19:07:48 version 1.11, 2003/04/15 19:10:00
Line 1611  sub render { Line 1611  sub render {
     my $var = $self->{'variable'};      my $var = $self->{'variable'};
           
     my $subdirFunc = eval('sub {' . $self->{'filechoice'} . '}');      my $subdirFunc = eval('sub {' . $self->{'filechoice'} . '}');
       die 'Error in resource filter code for variable ' . 
           {'variable'} . ', Perl said:' . $@ if $@;
   
     my $subdir = &$subdirFunc();      my $subdir = &$subdirFunc();
   
     my $filterFunc = $self->{FILTER_FUNC};      my $filterFunc = $self->{FILTER_FUNC};
Line 1718  sub postprocess { Line 1721  sub postprocess {
   
 1;  1;
   
   package Apache::lonhelper::section;
   
   =pod
   
   =head2 Element: section
   
   <section> allows the user to choose one or more sections from the current
   course.
   
   It takes the standard attributes "variable", "multichoice", and
   "nextstate", meaning what they do for most other elements.
   
   =cut
   
   no strict;
   @ISA = ("Apache::lonhelper::choices");
   use strict;
   
   BEGIN {
       &Apache::lonhelper::register('Apache::lonhelper::section',
                                    ('section'));
   }
   
   sub new {
       my $ref = Apache::lonhelper::choices->new();
       bless($ref);
   }
   
   sub start_section {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
       $paramHash->{CHOICES} = [];
   
       if ($target ne 'helper') {
           return '';
       }
       $paramHash->{'variable'} = $token->[2]{'variable'};
       $helper->declareVar($paramHash->{'variable'});
       $paramHash->{'multichoice'} = $token->[2]{'multichoice'};
       if (defined($token->[2]{'nextstate'})) {
           $paramHash->{'nextstate'} = $token->[2]{'nextstate'};
       }
   
       # Populate the CHOICES element
       my %choices;
   
       my $section = Apache::loncoursedata::CL_SECTION();
       my $classlist = Apache::loncoursedata::get_classlist();
       foreach (keys %$classlist) {
           my $sectionName = $classlist->{$_}->[$section];
           if (!$sectionName) {
               $choices{"No section assigned"} = "";
           } else {
               $choices{$sectionName} = $sectionName;
           }
       }
       
       for my $sectionName (sort(keys(%choices))) {
           push @{$paramHash->{CHOICES}}, [$sectionName, $sectionName];
       }
   
   }    
   
   sub end_section { return ''; }
   
   1;
   
 package Apache::lonhelper::general;  package Apache::lonhelper::general;
   
 =pod  =pod
Line 1748  be able to call methods on it. Line 1818  be able to call methods on it.
   
 BEGIN {  BEGIN {
     &Apache::lonhelper::register('Apache::lonhelper::general',      &Apache::lonhelper::register('Apache::lonhelper::general',
                                  'exec', 'condition', 'clause');                                   'exec', 'condition', 'clause',
                                    'eval');
 }  }
   
 sub start_exec {  sub start_exec {
Line 1762  sub start_exec { Line 1833  sub start_exec {
           
     $code = eval ('sub { my $helper = shift; my $state = shift; ' .      $code = eval ('sub { my $helper = shift; my $state = shift; ' .
         $code . "}");          $code . "}");
       die 'Error in <exec>, Perl said: '. $@ if $@;
     &$code($helper, $paramHash);      &$code($helper, $paramHash);
 }  }
   
Line 1799  sub start_clause { Line 1871  sub start_clause {
     my $clause = Apache::lonxml::get_all_text('/clause', $parser);      my $clause = Apache::lonxml::get_all_text('/clause', $parser);
     $clause = eval('sub { my $helper = shift; my $state = shift; '      $clause = eval('sub { my $helper = shift; my $state = shift; '
         . $clause . '}');          . $clause . '}');
       die 'Error in clause of condition, Perl said: ' . $@ if $@;
     if (!&$clause($helper, $paramHash)) {      if (!&$clause($helper, $paramHash)) {
         # Discard all text until the /condition.          # Discard all text until the /condition.
         &Apache::lonxml::get_all_text('/condition', $parser);          &Apache::lonxml::get_all_text('/condition', $parser);
Line 1807  sub start_clause { Line 1880  sub start_clause {
   
 sub end_clause { return ''; }  sub end_clause { return ''; }
   
   =pod
   
   =head2 General-purpose tag: <eval>
   
   The <eval> tag will be evaluated as a subroutine call passed in the
   current helper object and state hash as described in <condition> above,
   but is expected to return a string to be printed directly to the
   screen. This is useful for dynamically generating messages. 
   
   =cut
   
   # This is basically a type of message.
   # Programmatically setting $paramHash->{NEXTSTATE} would work, though
   # it's probably bad form.
   
   sub start_eval {
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
       if ($target ne 'helper') {
           return '';
       }
       
       my $program = Apache::lonxml::get_all_text('/eval', $parser);
       $program = eval('sub { my $helper = shift; my $state = shift; '
           . $program . '}');
       die 'Error in eval code, Perl said: ' . $@ if $@;
       $paramHash->{MESSAGE_TEXT} = &$program($helper, $paramHash);
   }
   
   sub end_eval { 
       my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   
       if ($target ne 'helper') {
           return '';
       }
   
       Apache::lonhelper::message->new();
   }
   
   
   
 1;  1;
   
 __END__  __END__

Removed from v.1.10  
changed lines
  Added in v.1.11


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>