cvsuser     02/02/05 14:21:27

  Modified:    P5EEx/Blue/P5EEx/Blue/Config File.pm
  Log:
  clean up. provide better error messages
  
  Revision  Changes    Path
  1.4       +39 -14    p5ee/P5EEx/Blue/P5EEx/Blue/Config/File.pm
  
  Index: File.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Config/File.pm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- File.pm   16 Jan 2002 18:32:47 -0000      1.3
  +++ File.pm   5 Feb 2002 22:21:27 -0000       1.4
  @@ -1,10 +1,10 @@
   
   #############################################################################
  -## $Id: File.pm,v 1.3 2002/01/16 18:32:47 spadkins Exp $
  +## $Id: File.pm,v 1.4 2002/02/05 22:21:27 spadkins Exp $
   #############################################################################
   
   package P5EEx::Blue::Config::File;
  -$VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.4 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   use P5EEx::Blue::P5EE;
   use P5EEx::Blue::Config;
  @@ -14,7 +14,15 @@
   
   sub create {
       my $self = shift;
  -    my $args = $self->SUPER::create(@_);
  +
  +    my ($args);
  +    if ($#_ >= 0 && ref($_[0]) eq "HASH") {
  +        $args = $_[0];
  +    }
  +    else {
  +        $args = {};
  +    }
  +
       local(*FILE);
   
       my ($file, $testfile, $dir, @files, $filebase, $filetype, $scriptbase);
  @@ -22,7 +30,8 @@
   
       $file = $args->{configFile};
       $file = $ENV{P5EE_CONFIG_FILE} if (!$file);
  -    $serializer_class = $ENV{P5EE_CONFIG_FILE_SERIALIZER};
  +    $serializer_class = $args->{configSerializerClass};
  +    $serializer_class = $ENV{P5EE_CONFIG_FILE_SERIALIZER} if (!$serializer_class);
   
       $dir = $0;
       if ($dir =~ m!/[^/]+$!) {
  @@ -37,6 +46,15 @@
       $scriptbase =~ s!.*/!!;        # remove leading path
       $scriptbase =~ s!\.[^\.]+$!!;  # remove trailing extension (i.e. ".cgi")
   
  +    if ($file) {
  +        # the file name was specified and it doesn't exist in the current
  +        # directory, so look in the script directory
  +        if (! -r $file && $dir ne ".") {
  +            $testfile = "$dir/$file";
  +            $file = $testfile if (-r $testfile);
  +        }
  +    }
  +
       if (!$file) {  # no file specified
           CONFIGFILE: foreach $filetype qw(pl xml ini properties perl conf) {
               foreach $filebase ($scriptbase, "config") {
  @@ -48,14 +66,6 @@
               }
           }
       }
  -    else {
  -        # the file name was specified and it doesn't exist in the current
  -        # directory, so look in the script directory
  -        if (! -r $file && $dir ne ".") {
  -            $testfile = "$dir/$file";
  -            $file = $testfile if (-r $testfile);
  -        }
  -    }
   
       if (!$file) {
           P5EEx::Blue::Exception::Config->throw(
  @@ -115,16 +125,31 @@
           eval "use $serializer_class;";
           if ($@) {
               P5EEx::Blue::Exception::Config->throw(
  -                error => "create(): error loading $serializer_class serializer 
class\n"
  +                error => "create(): error loading $serializer_class serializer 
class: $@\n"
               );
           }
           $conf = $serializer_class->deserialize($text);
  +        if (! %$conf) {
  +            P5EEx::Blue::Exception::Config->throw(
  +                error => "create(): $serializer_class produced empty config\n"
  +            );
  +        }
       }
       else { # don't bother with a serializer
           $conf = {};
  -        if ($text =~ /^\$[a-zA-Z][a-zA-Z0-9_]* *= *(\{.*\};[ \n]*)$/s) {
  +        if ($text =~ /^[ \t\n]*\$[a-zA-Z][a-zA-Z0-9_]* *= *(\{.*\};[ \n]*)$/s) {
               $text = "\$conf = $1";   # untainted now
               eval($text);
  +            if ($@) {
  +                P5EEx::Blue::Exception::Config->throw(
  +                    error => "create(): error eval'ing config text: $@\n"
  +                );
  +            }
  +        }
  +        else {
  +            P5EEx::Blue::Exception::Config->throw(
  +                error => "create(): config text doesn't start with '\$var ='\n"
  +            );
           }
       }
   
  
  
  


Reply via email to