]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Correctly preserve non-numeric version numbers
authorAilin Nemui <redacted>
Tue, 27 Jan 2015 21:07:16 +0000 (22:07 +0100)
committerAilin Nemui <redacted>
Wed, 28 Jan 2015 00:56:17 +0000 (01:56 +0100)
The YAML module that available in the Travis repos does not enforce
marking of numeric-looking variables as strings. When these are parsed
by the github site generator, precision is lost as they are interpreted
numerically (eg. version: 1.10 -> turns into 1.1).

Reported by Vilkku. Fixes #125

.travis.yml
_testing/_irssi_test.pl
_testing/travis/update-scripts-yaml.pl

index 1c69a58aaa33b9438551bf11b68ac09fe0417e05..a500e5c14a14e6e63bf661759ef881179426f365 100644 (file)
@@ -3,13 +3,13 @@ before_install:
 - sudo apt-get update -qq
 - sudo apt-get build-dep -qq irssi libperl-prereqscanner-perl libperl-critic-perl
   cpanminus
-- sudo apt-get install -qq lynx zsh apt-file libyaml-tiny-perl libtest-most-perl libgetopt-long-descriptive-perl
+- sudo apt-get install -qq lynx zsh apt-file libtest-most-perl libgetopt-long-descriptive-perl
   libwww-perl liblog-log4perl-perl libdatetime-perl libmodule-runtime-perl libparams-classify-perl
   libtime-duration-parse-perl
 - perl -V
 - wget -qO- https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm | sudo
   perl - App::cpanminus
-- sudo cpanm -q --skip-satisfied Perl::Critic Perl::PrereqScanner PPIx::XPath
+- sudo cpanm -q --skip-satisfied YAML::Tiny Perl::Critic Perl::PrereqScanner PPIx::XPath
 - git clone -q git://github.com/irssi/irssi irssi-head
 - pushd irssi-head
 - ./autogen.sh --with-perl=module 2>/dev/null | tail -n 17
index 1da8f59e25c56dd165d15e2cfdb7021d17a3401b..bcfcb3c849e6ebe02cb81aeb537f37c318c79b72 100644 (file)
@@ -18,6 +18,21 @@ Irssi::command('^window log off');
 my ($package) = grep { !/^_/ } keys %Irssi::Script::;
 
 require YAML::Tiny;
+YAML::Tiny->VERSION("1.59");
+require Encode;
+{
+    # This is an ugly hack to be `lax' about the encoding. We try to
+    # read everything as UTF-8 regardless of declared file encoding
+    # and fall back to Latin-1.
+    my $orig = YAML::Tiny->can("_has_internal_string_value");
+    *YAML::Tiny::_has_internal_string_value = sub {
+       my $ret = $orig->(@_);
+       use bytes;
+       $_[0] = Encode::decode_utf8($_[0], sub{pack 'U', +shift})
+           unless Encode::is_utf8($_[0]);
+       $ret
+    }
+}
 require Module::CoreList;
 require CPAN::Meta::Requirements;
 require Perl::PrereqScanner;
@@ -32,8 +47,7 @@ my (%info, $version);
 unless (defined $package) {
     my %fail = (failed => 1, name => $CURRENT_SCRIPT);
     $fail{modules} = \@modules if @modules;
-    { open my $ef, '>:utf8', "failed.yml";
-      print $ef YAML::Tiny::Dump([\%fail]); }
+    YAML::Tiny::DumpFile("failed.yml", [\%fail]);
     # Grep for the code instead
     require PPI;
     require PPIx::XPath;
@@ -74,5 +88,4 @@ if ($loginfo) {
 }
 $info{modules} = \@modules if @modules;
 $info{default_package} = $package =~ s/::$//r if $package;
-{ open my $ef, '>:utf8', "info.yml";
-  print $ef YAML::Tiny::Dump([\%info]); }
+YAML::Tiny::DumpFile("info.yml", [\%info]);
index 57620963c423620ad6610d8575bb4003484b31c2..0ed52aca5f5f7dc004324811d66c0234728cff0e 100644 (file)
@@ -1,19 +1,10 @@
 use strict; use warnings;
-use YAML::Tiny;
-use Scalar::Util;
-BEGIN {
-    sub YAML::Tiny::_has_internal_string_value {
-       !Scalar::Util::looks_like_number($_[0])
-    }
-}
+use YAML::Tiny 1.59;
 
-my @config;
-if (open my $ef, '<:utf8', '_testing/config.yml') {
-    @config = Load(do { local $/; <$ef> });
-}
+my $config = YAML::Tiny::LoadFile('_testing/config.yml');
 my @yaml_keys;
-if (@config) {
-    @yaml_keys = @{ $config[0]{scripts_yaml_keys}//[] };
+if ($config) {
+    @yaml_keys = @{ $config->{scripts_yaml_keys}//[] };
 }
 die "no keys defined in config.yaml\n" unless @yaml_keys;
 
@@ -75,14 +66,12 @@ my @newdoc = map {
         } sort @yaml_keys
     }
 } sort keys %newmeta;
-{ open my $ef, '>:utf8', '_data/scripts.yaml' or die $!;
-  print $ef Dump \@newdoc;
-}
+YAML::Tiny::DumpFile('_data/scripts.yaml', \@newdoc);
 
-if (@config && @{$config[0]{whitelist}//[]}) {
+if ($config && @{$config->{whitelist}//[]}) {
     my $changed;
     my @wl;
-    for my $sf (@{$config[0]{whitelist}}) {
+    for my $sf (@{$config->{whitelist}}) {
        if (-s "Test/$sf:passed") {
            $changed = 1;
        }
@@ -91,10 +80,8 @@ if (@config && @{$config[0]{whitelist}//[]}) {
        }
     }
     if ($changed) {
-       $config[0]{whitelist} = \@wl;
-       { open my $ef, '>:utf8', '_testing/config.yml' or die $!;
-         print $ef Dump @config;
-        }
+       $config->{whitelist} = \@wl;
+       YAML::Tiny::DumpFile('_testing/config.yml', $config);
     }
 }
 
git clone https://git.99rst.org/PROJECT