]> granicus.if.org Git - fortune-mod/commitdiff
refactoring
authorShlomi Fish <shlomif@shlomifish.org>
Tue, 18 Aug 2020 12:06:38 +0000 (15:06 +0300)
committerShlomi Fish <shlomif@shlomifish.org>
Wed, 16 Sep 2020 11:00:36 +0000 (14:00 +0300)
fortune-mod/fortune/process-fortune-man-template.pl

index 5c80fe0bcbd8ef45576eecdaf3c9b9a4161e2dfe..f8c3b306d7234d6dddb65bc6a57687eeddb666bb 100644 (file)
@@ -4,6 +4,21 @@ use strict;
 use warnings;
 use autodie;
 
+sub _utf8_slurp
+{
+    my $filename = shift;
+
+    open my $in, '<:encoding(utf-8)', $filename
+        or die "Cannot open '$filename' for slurping - $!";
+
+    local $/;
+    my $contents = <$in>;
+
+    close($in);
+
+    return $contents;
+}
+
 use File::Basename qw / dirname /;
 use File::Path qw / mkpath /;
 use Getopt::Long qw/ GetOptions /;
@@ -52,22 +67,13 @@ if ( $dirname and ( !-e $dirname ) )
 open my $out, '>:encoding(utf-8)', $output_fn;
 my $text = _utf8_slurp($input_fn);
 
-sub _utf8_slurp
+if ( ( $text =~ s#\Q[[cookiedir_placeholder]]\E#${cookiedir}#gms ) > 1 )
 {
-    my $filename = shift;
-
-    open my $in, '<:encoding(utf8)', $filename
-        or die "Cannot open '$filename' for slurping - $!";
-
-    local $/;
-    my $contents = <$in>;
-
-    close($in);
-
-    return $contents;
+    die "too many cookiedir_placeholder substitutions!";
+}
+if ( ( $text =~ s#\Q[[ocookiedir_placeholder]]\E#${ocookiedir}#gms ) > 1 )
+{
+    die "too many ocookiedir_placeholder substitutions!";
 }
-
-die if ( $text =~ s#\Q[[cookiedir_placeholder]]\E#${cookiedir}#gms ) > 1;
-die if ( $text =~ s#\Q[[ocookiedir_placeholder]]\E#${ocookiedir}#gms ) > 1;
 $out->print($text);
 close($out);