cvs commit: p5ee/App-Options/t file.txt app.conf main.t old.t test1.conf

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/05/20 12:27:14

  Modified:    App-Options CHANGES META.yml TODO
               App-Options/lib/App Options.pm
               App-Options/t app.conf main.t old.t test1.conf
  Added:       App-Options/t file.txt
  Log:
  here docs, file vars, line continuations
  
  Revision  Changes    Path
  1.12      +6 -0      p5ee/App-Options/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/CHANGES,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CHANGES	14 May 2005 14:14:01 -0000	1.11
  +++ CHANGES	20 May 2005 19:27:13 -0000	1.12
  @@ -2,8 +2,14 @@
   # CHANGE LOG
   #############################################################################
   
  +VERSION 0.97
  + x enable "here documents", var = <<EOF
  + x enable file/cmd variables, var = < filename (or "cmd|")
  + x allow line continuation chars, i.e. var = hello \\nworld
  +
   VERSION 0.96
    x cleaned up some of the --debug_options output
  + x tests run clean on Win32
    x used File::Spec to make file/directory manipulation platform-independent (i.e. Win32)
      NOTE: I used a mix of platform-independent File::Spec functions and explicit
      conversion from "\" paths to POSIX-compliant "/" paths.  This is because the
  
  
  
  1.4       +5 -5      p5ee/App-Options/META.yml
  
  Index: META.yml
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/META.yml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- META.yml	14 May 2005 14:14:01 -0000	1.3
  +++ META.yml	20 May 2005 19:27:13 -0000	1.4
  @@ -1,9 +1,9 @@
   ---
   name: App-Options
  -version: 0.95
  +version: 0.97
   author:
  -  - stephen.adkins.com
  -abstract: combine command line options, environment vars, and option file values
  +  - [email protected]
  +abstract: 'combine command line options, environment vars, and option file values'
   license: perl
   requires:
     Carp: 0
  @@ -15,5 +15,5 @@
   provides:
     App::Options:
       file: lib/App/Options.pm
  -    version: 0.95
  -generated_by: Module::Build version 0.2608
  +    version: 0.97
  +generated_by: Module::Build version 0.261
  
  
  
  1.11      +1 -4      p5ee/App-Options/TODO
  
  Index: TODO
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/TODO,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TODO	14 May 2005 14:14:01 -0000	1.10
  +++ TODO	20 May 2005 19:27:13 -0000	1.11
  @@ -18,9 +18,6 @@
          4 = [1+2+3] + file options not defined by program cause errors
    o allow for subclassing (App::Options::YAML, etc.) (split up the init() method)
    o save the init(@args) for later print_usage or later reparsing
  - o file/cmd variables, var = <FILE>filename (or "cmd|")
  - o here documents, var = <<EOF
  - o line continuation chars, i.e. var = hello \\nworld
    o setenv arg to set environment variables
    o make lots more tests (starting with the examples in the documentation)
    o make example scripts (starting with the examples in the documentation)
  
  
  
  1.17      +41 -5     p5ee/App-Options/lib/App/Options.pm
  
  Index: Options.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/lib/App/Options.pm,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Options.pm	14 May 2005 14:14:01 -0000	1.16
  +++ Options.pm	20 May 2005 19:27:13 -0000	1.17
  @@ -14,7 +14,7 @@
   use File::Spec;
   use Config;
   
  -$VERSION = "0.96";
  +$VERSION = "0.97";
   
   =head1 NAME
   
  @@ -537,7 +537,7 @@
   
           local(*App::Options::FILE);
           my ($option_file, $exclude_section);
  -        my ($cond, @cond, $exclude);
  +        my ($cond, @cond, $exclude, $heredoc_end);
           while ($#option_file > -1) {
               $option_file = shift(@option_file);
               if ($option_file =~ m!\$\{prefix\}!) {
  @@ -610,7 +610,43 @@
                       if (/^([a-zA-Z0-9_.-]+) *= *(.*)/) {  # untainting also happens
                           $var = $1;
                           $value = $2;
  -                        $value =~ s/^"(.*)"$/$1/;  # quoting, var = " hello world " (enables leading/trailing spaces)
  +
  +                        # "here documents": var = <<EOF ... EOF
  +                        if ($value =~ /^<<(.*)/) {
  +                            $heredoc_end = $1;
  +                            $value = "";
  +                            while (<App::Options::FILE>) {
  +                                last if ($_ =~ /^$heredoc_end\s*$/);
  +                                $value .= $_;
  +                            }
  +                            $heredoc_end = "";
  +                        }
  +                        # get value from a file
  +                        elsif ($value =~ /^<\s*(.+)/ || $value =~ /^(.+)\s*\|$/) {
  +                            $value =~ s/\$\{([a-zA-Z0-9_\.-]+)\}/(defined $values->{$1} ? $values->{$1} : "")/eg;
  +                            if (open(App::Options::FILE2, $value)) {
  +                                $value = join("", <App::Options::FILE2>);
  +                                close(App::Options::FILE2);
  +                            }
  +                            else {
  +                                $value = "Can't read file [$value] for variable [$var]: $!";
  +                            }
  +                        }
  +                        # get additional line(s) due to continuation chars
  +                        elsif ($value =~ s/\s*\\\s*$/\n/) {
  +                            while (<App::Options::FILE>) {
  +                                if ($_ =~ s/\s*\\\s*$/\n/) {
  +                                    $value .= $_;
  +                                }
  +                                else {
  +                                    $value .= $_;
  +                                    last;
  +                                }
  +                            }
  +                        }
  +                        else {
  +                            $value =~ s/^"(.*)"$/$1/;  # quoting, var = " hello world " (enables leading/trailing spaces)
  +                        }
   
                           print STDERR "       Var Found in File : var=[$var] value=[$value]\n" if ($debug_options >= 6);
                           
  
  
  
  1.7       +14 -0     p5ee/App-Options/t/app.conf
  
  Index: app.conf
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/t/app.conf,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- app.conf	14 May 2005 14:04:22 -0000	1.6
  +++ app.conf	20 May 2005 19:27:14 -0000	1.7
  @@ -1,3 +1,4 @@
  +testdir = t
   var = value
   #prefix = /usr/local
   envtest = xy$ENV{ZZ}y
  @@ -35,3 +36,16 @@
   [/ol/]
   var7 = value7
   [host=xyzzy3] hosttest = you really named a host xyzzy3?
  +[ALL]
  +var21 = < ${testdir}/file.txt
  +var22 = <${testdir}/file.txt   
  +var23 = cat ${testdir}/file.txt |
  +var24 = <<EOF
  +This is text
  +and more text
  +EOF 
  +var25 = This is text \
  +and more text
  +var26 = normal
  +
  +flush_imports = 1
  
  
  
  1.8       +25 -2     p5ee/App-Options/t/main.t
  
  Index: main.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/t/main.t,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- main.t	14 May 2005 14:04:22 -0000	1.7
  +++ main.t	20 May 2005 19:27:14 -0000	1.8
  @@ -21,6 +21,10 @@
   $dir = ".";
   $dir = "t" if (! -f "app.conf");
   
  +BEGIN {
  +    $App::options{testdir} = (-f "app.conf") ? "." : "t";
  +}
  +
   use App::Options (
       option => {
           var10 => { env => "VAR10a;VAR10", },
  @@ -54,10 +58,27 @@
   is($App::options{var12}, "value12", "specified env var works");
   is($App::options{var10}, "value10", "specified secondary env var works");
   
  +open(FILE2, "< $dir/file.txt");
  +$file_txt = join("", <FILE2>);
  +close(FILE2);
  +
  +is($App::options{var21}, $file_txt, "value from file");
  +is($App::options{var22}, $file_txt, "value from file (2)");
  +ok($App::options{var23} eq $file_txt || $App::options{var23} =~ /open/, "value from command");
  +
  +$var24 = <<EOF;
  +This is text
  +and more text
  +EOF
  +is($App::options{var24}, $var24, "value from here doc");
  +is($App::options{var25}, $var24, "value from line continuations");
  +is($App::options{var26}, "normal", "back to normal");
  +
   %App::options = (
  -    config_file => "$dir/app.conf",
  +    config_file => "app.conf",
       prefix => "/usr/local",
  -    perlinc => "/usr/mycompany/2.1.7/lib/perl5"
  +    perlinc => "/usr/mycompany/2.1.7/lib/perl5",
  +    testdir => (-f "app.conf") ? "." : "t",
   );
   
   App::Options->init();
  @@ -70,6 +91,7 @@
   is($App::options{var2}, "old pattern match", "old pattern match");
   is($INC[0], "/usr/mycompany/2.1.7/lib/perl5", "\@INC affected by perlinc");
   
  +$App::otherconf{testdir} = (-f "app.conf") ? "." : "t";
   App::Options->init(\%App::otherconf);
   #print "CONF:\n   ", join("\n   ",%App::otherconf), "\n";
   ok(%App::otherconf, "put something in %App::otherconf");
  @@ -79,6 +101,7 @@
   is($App::otherconf{var1}, "pattern match", "pattern match");
   is($App::otherconf{var2}, "old pattern match", "old pattern match");
   
  +$App::options3{testdir} = (-f "app.conf") ? "." : "t";
   App::Options->init(values => \%App::options3);
   #print "CONF:\n   ", join("\n   ",%App::options3), "\n";
   ok(%App::options3, "put something in %App::options3");
  
  
  
  1.3       +8 -2      p5ee/App-Options/t/old.t
  
  Index: old.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/t/old.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- old.t	14 May 2005 14:04:22 -0000	1.2
  +++ old.t	20 May 2005 19:27:14 -0000	1.3
  @@ -19,6 +19,9 @@
   $ENV{APP_VAR11} = "value11";
   $ENV{VAR12} = "value12";
   
  +BEGIN {
  +    $App::options{testdir} = (-f "app.conf") ? "." : "t";
  +}
   App::Options->init(
       option => {
           var10 => { env => "VAR10a;VAR10", },
  @@ -32,7 +35,7 @@
   
   #print "CONF:\n   ", join("\n   ",%App::options), "\n";
   ok(%App::options, "put something in %App::options");
  -is($App::options{prefix}, $prefix, "prefix = $prefix");
  +#is($App::options{prefix}, $prefix, "prefix = $prefix");
   is($App::options{app}, "old", "app = old");
   is($App::options{var}, "value", "var = value");
   is($App::options{var1}, "pattern match", "pattern match");
  @@ -55,7 +58,8 @@
   %App::options = (
       config_file => "$dir/app.conf",
       prefix => "/usr/local",
  -    perlinc => "/usr/mycompany/2.1.7/lib/perl5"
  +    perlinc => "/usr/mycompany/2.1.7/lib/perl5",
  +    testdir => (-f "app.conf") ? "." : "t",
   );
   
   App::Options->init();
  @@ -68,6 +72,7 @@
   is($App::options{var2}, "old pattern match", "old pattern match");
   is($INC[0], "/usr/mycompany/2.1.7/lib/perl5", "\@INC affected by perlinc");
   
  +$App::otherconf{testdir} = (-f "app.conf") ? "." : "t";
   App::Options->init(\%App::otherconf);
   #print "CONF:\n   ", join("\n   ",%App::otherconf), "\n";
   ok(%App::otherconf, "put something in %App::otherconf");
  @@ -77,6 +82,7 @@
   is($App::otherconf{var1}, "pattern match", "pattern match");
   is($App::otherconf{var2}, "old pattern match", "old pattern match");
   
  +$App::options3{testdir} = (-f "app.conf") ? "." : "t";
   App::Options->init(values => \%App::options3);
   #print "CONF:\n   ", join("\n   ",%App::options3), "\n";
   ok(%App::options3, "put something in %App::options3");
  
  
  
  1.2       +1 -1      p5ee/App-Options/t/test1.conf
  
  Index: test1.conf
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Options/t/test1.conf,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test1.conf	16 Nov 2003 21:21:22 -0000	1.1
  +++ test1.conf	20 May 2005 19:27:14 -0000	1.2
  @@ -1,4 +1,4 @@
   
  -perlinc = /usr/rubicon/devel/src/p5ee/App-BEGIN/lib
  +perlinc = /usr/rubicon/devel/src/p5ee/App-Options/lib
   flush_imports = 1
   
  
  
  
  1.1                  p5ee/App-Options/t/file.txt
  
  Index: file.txt
  ===================================================================
  
  The quick brown
  fox 
    jumps over the lazy
  
    dog .
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.