cvs commit: p5ee/App-Options/lib/App Options.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     04/09/02 14:06:57

  Modified:    App-Options/lib/App Options.pm
  Log:
  tweak show_all, remove app_path_info
  
  Revision  Changes    Path
  1.8       +37 -34    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.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- Options.pm	17 Apr 2004 13:51:08 -0000	1.7
  +++ Options.pm	2 Sep 2004 21:06:57 -0000	1.8
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Options.pm,v 1.7 2004/04/17 13:51:08 spadkins Exp $
  +## $Id: Options.pm,v 1.8 2004/09/02 21:06:57 spadkins Exp $
   #############################################################################
   
   package App::Options;
  @@ -193,7 +193,7 @@
   
       App::Options->init(
           values => \%MyPackage::options,
  -        options => [ "option_file", "prefix", "app", "app_path_info",
  +        options => [ "option_file", "prefix", "app",
                        "perlinc", "debug_options", "import", ],
           option => {
               option_file   => "~/.app/app.conf",         # set default
  @@ -266,9 +266,6 @@
          was run (or the first part of PATH_INFO) if it is not supplied at
          the outset as an argument.
   
  -    app_path_info - this is the remainder of PATH_INFO after the first
  -       part is taken off to make the app.
  -
       prefix - This represents the base directory of the software
          installation (i.e. "/usr/myproduct/1.3.12").  If it is not
          set explicitly, it is detected from the following places:
  @@ -376,29 +373,7 @@
       }
   
       #################################################################
  -    # 2. find the app.
  -    #    by default this is the basename of the program
  -    #    in a web application, this is overridden by any existing
  -    #    first part of the PATH_INFO
  -    #################################################################
  -    my $app = $values->{app};
  -    my $app_path_info = $ENV{PATH_INFO} || "";
  -    $app_path_info =~ s!/+$!!;    # strip off trailing slashes ("/")
  -    if (!$app) {
  -        if ($app_path_info && $app_path_info =~ s!^/([^/]+)!!) {
  -            $app = $1;            # last part of PATH_INFO (without slashes)
  -        }
  -        else {
  -            $app = $0;            # start with the full script path
  -            $app =~ s!.*/!!;      # strip off leading path
  -            $app =~ s/\.[^.]+$//; # strip off trailing file type (i.e. ".pl")
  -        }
  -        $values->{app} = $app;
  -    }
  -    $values->{app_path_info} = $app_path_info;
  -
  -    #################################################################
  -    # 3. find the directory the program was run from.
  +    # 2. find the directory the program was run from.
       #    we will use this directory to search for the
       #    option file.
       #################################################################
  @@ -414,7 +389,7 @@
       }
   
       #################################################################
  -    # 4. guess the "prefix" directory for the entire
  +    # 3. guess the "prefix" directory for the entire
       #    software installation.  The program is usually in
       #    $prefix/bin or $prefix/cgi-bin.
       #################################################################
  @@ -439,6 +414,32 @@
   
       $prefix = "/usr/local" if (!$prefix);   # last resort: current directory
   
  +    #################################################################
  +    # 4. find the app.
  +    #    by default this is the basename of the program
  +    #    in a web application, this is overridden by any existing
  +    #    first part of the PATH_INFO
  +    #################################################################
  +    my $app = $values->{app};
  +    my $path_info = $ENV{PATH_INFO} || "";
  +    $path_info =~ s!/+$!!;    # strip off trailing slashes ("/")
  +    if (!$app) {
  +        if ($path_info && $path_info =~ s!^/([^/]+)!!) {
  +            my $path_info_app = $1;  # first part of PATH_INFO (without slashes)
  +            if ( ($ENV{HOME} && -f "$ENV{HOME}/.app/$path_info_app.conf") ||
  +                 (-f "$prog_dir/$path_info_app.conf") ||
  +                 (-f "$prefix/etc/app/$path_info_app.conf") ) {
  +                $app = $path_info_app;
  +            }
  +        }
  +        if (!$app) {
  +            $app = $0;            # start with the full script path
  +            $app =~ s!.*/!!;      # strip off leading path
  +            $app =~ s/\.[^.]+$//; # strip off trailing file type (i.e. ".pl")
  +        }
  +        $values->{app} = $app;
  +    }
  +
       my ($env_var, @env_vars, $regexp);
       if (! $init_args{no_option_file}) {
           #################################################################
  @@ -527,7 +528,7 @@
                           # only add values which have never been defined before
                           if (!defined $values->{$var}) {
                               if (!$init_args{no_env_vars}) {
  -                                if ($option && defined $option->{$var}{env}) {
  +                                if ($option && defined $option->{$var} && defined $option->{$var}{env}) {
                                       if ($option->{$var}{env} eq "") {
                                           @env_vars = ();
                                       }
  @@ -1476,15 +1477,17 @@
               "first_name", "last_name", "birth_dt", "company_id",
               "wholesale_ind", "change_dttm",
           ],
  -        show_all => 0,
  +        show_all => 1,
       );
   
   Using the "options" arg causes the options to
   be printed in the order given in the "--help" output.  Then the
   remaining options defined in the "option" arg are printed in 
  -alphabetical order.  Finally, all other options which are set
  -on the command line or in option files are printed unless
  -the "show_all => 0" argument is provided.
  +alphabetical order.  All other options which are set
  +on the command line or in option files are printed if the
  +"show_all" option is set.  This option is off by default if
  +either the "options" arg or the "option" arg are supplied
  +and on if neither are supplied.
   
   If, for some reason, the program needed to put the options
   into a different option hash (instead of %App::options) or directly
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.