[system] / trunk / pg / macros / parserAutoStrings.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/parserAutoStrings.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5556 - (download) (as text) (annotate)
Thu Oct 4 16:40:49 2007 UTC (12 years, 4 months ago) by sh002i
File size: 2557 byte(s)
added standard copyright/license header

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright  2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork2/lib/WeBWorK.pm,v 1.100 2007/08/13 22:59:53 sh002i Exp $
    5 #
    6 # This program is free software; you can redistribute it and/or modify it under
    7 # the terms of either: (a) the GNU General Public License as published by the
    8 # Free Software Foundation; either version 2, or (at your option) any later
    9 # version, or (b) the "Artistic License" which comes with this package.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 =head1 NAME
   18 
   19 parserAutoStrings.pl - Force String() to accpet any string.
   20 
   21 =head1 DESCRIPTION
   22 
   23 This file allows you to force String() to accept ANY string as a
   24 legal value.  (It will add the string to the context if it isn't
   25 already defined.)
   26 
   27 To acocmplish this, put the lines
   28 
   29   loadMacros("parserAutoStrings.pl");
   30   AutoStrings();
   31 
   32 (You can also pass AutoStrings a context pointer if you wish to
   33 alter context other than the current one.)
   34 
   35 There is also a routine to help making strings easier to predefine.
   36 For example:
   37 
   38   loadMacros("parserAutoStrings.pl");
   39   DefineStrings("string1","string2");
   40 
   41 would define two new strings (string1 and string2).  You can pass
   42 a context reference as the first argument to add strings to that
   43 context rather than the active one.
   44 
   45 =cut
   46 
   47 sub _parserAutoStrings_init {}
   48 
   49 ######################################################################
   50 
   51 sub AutoStrings {(shift || Value->context)->{value}{"String()"} = "parser::AutoStrings"};
   52 
   53 sub DefineStrings {
   54   my $context = (Value::isContext($_[0]) ? shift : Value->context);
   55   foreach my $x (@_)
   56     {$context->strings->add($x=>{}) unless defined $context->{strings}{$x}}
   57 }
   58 
   59 ######################################################################
   60 
   61 package parser::AutoStrings;
   62 our @ISA = ("Value::String");
   63 
   64 sub new {
   65   my $self = shift; my $class = ref($self) || $self;
   66   my $context = (Value::isContext($_[0]) ? shift : $self->context);
   67   my $x = join('',@_);
   68   $context->strings->add($x=>{}) unless defined $context->{strings}{$x};
   69   $self->SUPER::new($x);
   70 }
   71 
   72 ######################################################################
   73 
   74 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9