Changeset 2500 in ProjectBuilder


Ignore:
Timestamp:
Apr 1, 2020, 2:25:15 AM (4 years ago)
Author:
Bruno Cornec
Message:

fix pb_version_init call and dpfunc/ldfunc declaration in init

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/Conf.pm

    r2494 r2500  
    2222# Inherit from the "Exporter" module which handles exporting functions.
    2323 
    24 use vars qw($VERSION $REVISION $PBCONFVER @ISA @EXPORT);
     24use vars qw(@ISA @EXPORT);
    2525use Exporter;
    2626 
     
    3030our @ISA = qw(Exporter);
    3131our @EXPORT = qw(pb_conf_init pb_conf_add pb_conf_read pb_conf_read_if pb_conf_write pb_conf_get pb_conf_get_if pb_conf_get_all pb_conf_get_hash pb_conf_cache pb_conf_update_v0 pb_conf_get_in_hash_if);
    32 ($VERSION,$REVISION,$PBCONFVER) = pb_version_init();
    3332
    3433# Global hash of conf files
     
    4342# We consider that values can not change during the life of pb
    4443my $h = ();
     44
     45my $dpfunc;
     46my $ldfunc;
     47our ($VERSION,$REVISION,$PBCONFVER) = pb_version_init();
    4548
    4649=pod
     
    146149my $proj=shift;
    147150
    148 pb_log(1,"Entering pb_conf_init\n");
     151pb_log(2,"Entering pb_conf_init\n");
    149152#
    150153# Check project name
     
    165168}
    166169pb_log(1,"PBPROJ = $ENV{'PBPROJ'}\n");
     170
     171# Manage YAML modules to use
     172
     173if ($PBCONFVER >= 1) {
     174    eval {
     175        require YAML::XS;
     176        YAML::XS->import();
     177    };
     178    if ($@) {
     179        eval {
     180            require YAML;
     181            YAML->import();
     182        };
     183        if ($@) {
     184            eval {
     185                # No YAML found using a more std but less complete one. Old perl only
     186                require Module::Build::YAML;
     187                Module::Build::YAML->import();
     188            };
     189            if ($@) {
     190                eval {
     191                    # No YAML found using a more std but less complete one. Old perl only
     192                    require YAML::Tiny;
     193                    YAML::Tiny->import();
     194                };
     195                if ($@) {
     196                    # Here we should be in the setup phase, with an embedded YAML code
     197                    $dpfunc = \&pb_Dump;
     198                    $ldfunc = \&pb_LoadFile;
     199                    #die "Unable to handle YAML configuration files without a YAML.pm module\n";
     200                } else {
     201                    $dpfunc = \&YAML::Tiny::Dump;
     202                    $ldfunc = \&YAML::Tiny::LoadFile;
     203                }
     204            } else {
     205                $dpfunc = \&Module::Build::YAML::Dump;
     206                $ldfunc = \&Module::Build::YAML::LoadFile;
     207            }
     208        } else {
     209            $dpfunc = \&YAML::Dump;
     210            $ldfunc = \&YAML::LoadFile;
     211        }
     212    } else {
     213        $dpfunc = \&YAML::XS::Dump;
     214        $ldfunc = \&YAML::XS::LoadFile;
     215    }
     216}
    167217}
    168218
     
    180230my $cf = shift;
    181231my $lh = shift;
    182 
    183 my $ldfunc;
    184232
    185233# Read the content of the config file and cache it in the %h hash then available for queries
     
    208256    }
    209257    close(CONF);
     258
    210259} else {
    211     eval {
    212         require YAML::XS;
    213         YAML::XS->import();
    214     };
    215     if ($@) {
    216         eval {
    217             require YAML;
    218             YAML->import();
    219         };
    220         if ($@) {
    221             eval {
    222                 # No YAML found using a more std but less complete one. Old perl only
    223                 require Module::Build::YAML;
    224                 Module::Build::YAML->import();
    225             };
    226             if ($@) {
    227                 eval {
    228                     # No YAML found using a more std but less complete one. Old perl only
    229                     require YAML::Tiny;
    230                     YAML::Tiny->import();
    231                 };
    232                 if ($@) {
    233                     eval {
    234                         # No YAML found using an embedded pne
    235                         require ProjectBuilder::YAML;
    236                         ProjectBuilder::YAML->import();
    237                     };
    238                     if ($@) {
    239                         # Here we should be in the setup phase, with an embedded YAML code
    240                         $ldfunc = \&LoadFile;
    241                         #die "Unable to handle YAML configuration files without a YAML.pm module\n";
    242                     } else {
    243                         $ldfunc = \&ProjectBuilder::YAML::LoadFile;
    244                     }
    245                 } else {
    246                     $ldfunc = \&YAML::Tiny::LoadFile;
    247                 }
    248             } else {
    249                 $ldfunc = \&Module::Build::YAML::LoadFile;
    250             }
    251         } else {
    252             $ldfunc = \&YAML::LoadFile;
    253         }
    254     } else {
    255         $ldfunc = \&YAML::XS::LoadFile;
    256     }
    257 
    258260    # Have we already handled that conf file ?
    259261    next if ((defined $lh) && (defined $lh->{'__cf'}) && (defined $lh->{'__cf'}->{$cf}) && ($lh->{'__cf'}->{$cf} eq 1));
     
    366368my $conffile = shift;
    367369my $h = shift;
    368 my $dpfunc;
    369370
    370371confess "No configuration file defined to write into !" if (not defined $conffile);
     
    381382    }
    382383} else {
    383     # This is the new YAML format
    384     eval {
    385         require YAML::XS;
    386         YAML::XS->import();
    387     };
    388     if ($@) {
    389         eval {
    390             require YAML;
    391             YAML->import();
    392         };
    393         if ($@) {
    394             eval {
    395                 # No YAML found using a more std but less complete one. Old perl only
    396                 require Module::Build::YAML;
    397                 Module::Build::YAML->import();
    398             };
    399             if ($@) {
    400                 eval {
    401                     # No YAML found using a more std but less complete one. Old perl only
    402                     require YAML::Tiny;
    403                     YAML::Tiny->import();
    404                 };
    405                 if ($@) {
    406                     eval {
    407                         # No YAML found using an embedded pne
    408                         require ProjectBuilder::YAML;
    409                         ProjectBuilder::YAML->import();
    410                     };
    411                     if ($@) {
    412                         # Here we should be in the setup phase, with an embedded YAML code
    413                         $dpfunc = \&LoadFile;
    414                         #die "Unable to handle YAML configuration files without a YAML.pm module\n";
    415                     } else {
    416                         $dpfunc = \&ProjectBuilder::YAML::Dump;
    417                     }
    418                 } else {
    419                     $dpfunc = \&YAML::Tiny::Dump;
    420                 }
    421             } else {
    422                 $dpfunc = \&Module::Build::YAML::Dump;
    423             }
    424         } else {
    425             $dpfunc = \&YAML::Dump;
    426         }
    427     } else {
    428         $dpfunc = \&YAML::XS::Dump;
    429     }
    430 
    431384    pb_log(1,"Writing YAML conf file $conffile\n");
    432385    delete $h->{'__cf'};
Note: See TracChangeset for help on using the changeset viewer.