[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 5551 - (download) (as text) (annotate)
Tue Oct 2 20:48:05 2007 UTC (12 years, 2 months ago) by sh002i
File size: 1628 byte(s)
improved formatting for docs -- these were in pod sections but were all
formatted as verbatim sections, and i moved them into normal paragraphs,
lists, etc. should make things more readable from the web.

    1 =head1 NAME
    2 
    3 parserAutoStrings.pl - Force String() to accpet any string.
    4 
    5 =head1 DESCRIPTION
    6 
    7 This file allows you to force String() to accept ANY string as a
    8 legal value.  (It will add the string to the context if it isn't
    9 already defined.)
   10 
   11 To acocmplish this, put the lines
   12 
   13     loadMacros("parserAutoStrings.pl");
   14     AutoStrings();
   15 
   16 (You can also pass AutoStrings a context pointer if you wish to
   17 alter context other than the current one.)
   18 
   19 There is also a routine to help making strings easier to predefine.
   20 For example:
   21 
   22     loadMacros("parserAutoStrings.pl");
   23     DefineStrings("string1","string2");
   24 
   25 would define two new strings (string1 and string2).  You can pass
   26 a context reference as the first argument to add strings to that
   27 context rather than the active one.
   28 
   29 =cut
   30 
   31 sub _parserAutoStrings_init {}
   32 
   33 ######################################################################
   34 
   35 sub AutoStrings {(shift || Value->context)->{value}{"String()"} = "parser::AutoStrings"};
   36 
   37 sub DefineStrings {
   38   my $context = (Value::isContext($_[0]) ? shift : Value->context);
   39   foreach my $x (@_)
   40     {$context->strings->add($x=>{}) unless defined $context->{strings}{$x}}
   41 }
   42 
   43 ######################################################################
   44 
   45 package parser::AutoStrings;
   46 our @ISA = ("Value::String");
   47 
   48 sub new {
   49   my $self = shift; my $class = ref($self) || $self;
   50   my $context = (Value::isContext($_[0]) ? shift : $self->context);
   51   my $x = join('',@_);
   52   $context->strings->add($x=>{}) unless defined $context->{strings}{$x};
   53   $self->SUPER::new($x);
   54 }
   55 
   56 ######################################################################
   57 
   58 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9