From fdbaaaa548f907fe5ce67705395e1b7a6ae3ec2a Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Fri, 22 Dec 2017 15:14:46 -0500 Subject: [PATCH] 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. --- modules/ksb/KDEProjectsReader.pm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/ksb/KDEProjectsReader.pm b/modules/ksb/KDEProjectsReader.pm index 9ad0f2a..90aa17d 100644 --- a/modules/ksb/KDEProjectsReader.pm +++ b/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 => { },