use Regexp::Common; { my $shebang_re = qr/#!\S*/; my $bareword_re = qr/[[:word:]]+/; my $quoted_re = $RE{quoted}; my $comma_re = qr/(?:=>|,)/; my $n_re = qr/\s*(?:\n|\r)?\s*/; my $pair_re = qr/\s*$bareword_re\s*$comma_re\s*(?:$bareword_re|$quoted_re)/; my $hash_body_re = qr/\s*{\s*(?:$pair_re\s*$comma_re\s*)*\s*(?:$pair_re\s*$comma_re?\s*)\s*}\s*/; my $comment_re = qr/(?:^\s*#.*$n_re)*/m; my $hash_re = qr/\s*$comment_re?\s*$bareword_re\s*$comma_re\s*$hash_body_re\s*/; my $hashes_re = qr/\s*(?:$hash_re\s*$comma_re)*\s*(?:$hash_re\s*$comma_re?\s*)/; my $conf_re = qr/$shebang_re?\s*$hashes_re\s*/; sub _untaint_config { my $_conf = shift; my ($conf) = $_conf =~ /^($conf_re)$/sm; return $conf; } # testing hooks if ( $ENV{HARNESS_ACTIVE} ) { *_comma_re = sub { $comma_re }; *_comment_re = sub { $comment_re }; *_pair_re = sub { $pair_re }; *_hash_body_re = sub { $hash_body_re }; *_conf_re = sub { $conf_re }; } }