chiark / gitweb /
Fix use of non-scalar state vars in older perls, move complex inline tokenizer regexp...
authorJeff Ober <jober@ziprecruiter.com>
Fri, 17 Jan 2020 15:15:40 +0000 (10:15 -0500)
committerJeff Ober <jober@ziprecruiter.com>
Fri, 17 Jan 2020 15:15:40 +0000 (10:15 -0500)
lib/TOML/Tiny/Tokenizer.pm

index 8b584851f7e1e15450ccedad84e9275794bb8d23..012838f51d93daa68abc9461b88b3ebea71d6369 100644 (file)
@@ -52,6 +52,8 @@ sub next_token {
   my $token;
 
   state $key = qr/(?&Key) $TOML/x;
+  state $table = qr/\G \[ [\x20 \x09]* ($key) [\x20 \x09]* \] [\x20 \x09]* (?= (:? \x23 .* )? (?: \x0D? \x0A) | $ )/x;
+  state $array_table = qr/\G \[\[ [\x20 \x09]* ($key) [\x20 \x09]* \]\] [\x20 \x09]* (?= (:? \x23 .* )? (?: \x0D? \x0A) | $ )/x;
 
   while ($self->{position} < $self->{last_position} && !$token) {
     my $prev = $self->prev_token_type;
@@ -69,11 +71,11 @@ sub next_token {
       }
 
       if ($newline) {
-        when (/\G \[ [\x20 \x09]* ($key) [\x20 \x09]* \] [\x20 \x09]* (?= (:? \x23 .* )? (?: \x0D? \x0A) | $ )/xgc) {
+        when (/$table/xgc) {
           $token = $self->_make_token('table', $self->tokenize_key($1));
         }
 
-        when (/\G \[\[ [\x20 \x09]* ($key) [\x20 \x09]* \]\] [\x20 \x09]* (?= (:? \x23 .* )? (?: \x0D? \x0A) | $ )/xgc) {
+        when (/$array_table/xgc) {
           $token = $self->_make_token('array_table', $self->tokenize_key($1));
         }
       }
@@ -231,7 +233,7 @@ sub tokenize_string {
 }
 
 sub unescape_chars {
-  state %esc = (
+  state $esc = {
     '\b'   => "\x08",
     '\t'   => "\x09",
     '\n'   => "\x0A",
@@ -240,10 +242,10 @@ sub unescape_chars {
     '\"'   => "\x22",
     '\/'   => "\x2F",
     '\\\\' => "\x5C",
-  );
+  };
 
-  if (exists $esc{$_[0]}) {
-    return $esc{$_[0]};
+  if (exists $esc->{$_[0]}) {
+    return $esc->{$_[0]};
   }
 
   my $hex = hex substr($_[0], 2);