kde-projects: Fix runtime check for YAML modules.

My attempt to make the KDEProjectReader's check for YAML be a runtime check was
thwarted because I had separately used a "use KDEProjectReader" elsewhere,
which Perl ensures happens at compile time.

Instead make the check part of the constructor so that the package can at least
compile without throwing an error.
wilder
Michael Pyne 8 years ago
parent 62b5614f9b
commit fdbaaaa548
  1. 27
      modules/ksb/KDEProjectsReader.pm

@ -11,22 +11,25 @@ use 5.014;
use File::Find;
sub _verifyYAMLModuleLoaded
{
# Load YAML-reading module if available without causing compile error if it
# isn't. Note that YAML::Tiny and YAML do not work since some metadata files
# use features it doesn't support
my @YAML_Opts = qw(Dump Load LoadFile);
my @YAML_Mods = qw(YAML::XS YAML::Syck YAML::PP);
my $success = 0;
my @YAML_Opts = qw(Dump Load LoadFile);
my @YAML_Mods = qw(YAML::XS YAML::Syck YAML::PP);
my $success = 0;
foreach my $mod (@YAML_Mods) {
$success ||= eval "require $mod; $mod->import(\@YAML_Opts); 1;";
last if $success;
}
foreach my $mod (@YAML_Mods) {
$success ||= eval "require $mod; $mod->import(\@YAML_Opts); 1;";
last if $success;
}
if (!$success) {
die "Unable to load one of " .
join(', ', @YAML_Mods) .
" modules, one of which is needed to handle KDE project data.";
if (!$success) {
die "Unable to load one of " .
join(', ', @YAML_Mods) .
" modules, one of which is needed to handle KDE project data.";
}
}
# Method: new
@ -45,6 +48,8 @@ sub new
my $projectMetadataModule = shift;
my $desiredProtocol = shift;
_verifyYAMLModuleLoaded();
my $self = {
# Maps short names to repo info blocks
repositories => { },

Loading…
Cancel
Save