From 2975b73a120373356cfd64cb985a1ecbd2b10f45 Mon Sep 17 00:00:00 2001
From: Mark Tompsett <mtompset@hotmail.com>
Date: Tue, 7 Nov 2017 03:21:36 +0000
Subject: [PATCH] [SIGNED-OFF] [SIGNED-OFF] Bug 17770: Improve perlcritic level

before patch: perlcritic -4 noisy
after patch: perlcritic -4 ok

Signed-off-by: Your Full Name <your_email>

Signed-off-by: Jon Knight <J.P.Knight@lboro.ac.uk>
---
 t/db_dependent/Sitemapper.t | 57 +++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 25 deletions(-)

diff --git a/t/db_dependent/Sitemapper.t b/t/db_dependent/Sitemapper.t
index 4c5e741..3dc9b48 100755
--- a/t/db_dependent/Sitemapper.t
+++ b/t/db_dependent/Sitemapper.t
@@ -24,7 +24,7 @@ use DateTime;
 use Test::MockModule;
 use Test::More tests => 16;
 use Koha::Schema;
-
+use Carp qw/croak carp/;
 
 BEGIN {
     use_ok('Koha::Sitemapper');
@@ -37,7 +37,7 @@ $mocked_datetime->mock('now', sub { return $now_value; } );
 
 sub slurp {
     my $file = shift;
-    open my $fh, '<', $file or die;
+    open my $fh, '<', $file or croak;
     local $/ = undef;
     my $cont = <$fh>;
     close $fh;
@@ -51,9 +51,10 @@ sub fixtures {
     fixtures_ok [
         Biblio => [
             [ qw/ biblionumber datecreated timestamp  / ],
-            @$data,
+            @{$data},
         ],
     ], 'add fixtures';
+    return;
 }
 
 # Make the code in the module use our mocked Koha::Schema/Koha::Database
@@ -81,10 +82,10 @@ my $sitemapper = Koha::Sitemapper->new(
 $sitemapper->run();
 
 my $file = "$dir/sitemapindex.xml";
-ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml created");
+ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml created');
 my $file_content = slurp($file);
 my $now = DateTime->now->ymd;
-my $expected_content = <<EOS;
+my $expected_content = <<"EOS";
 <?xml version="1.0" encoding="UTF-8"?>
 
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@@ -95,12 +96,12 @@ my $expected_content = <<EOS;
 </sitemapindex>
 EOS
 chop $expected_content;
-is( $file_content, $expected_content, "Its content is valid" );
+is( $file_content, $expected_content, 'Its content is valid' );
 
 $file = "$dir/sitemap0001.xml";
-ok( -e $file, "File sitemap0001.xml created");
+ok( -e $file, 'File sitemap0001.xml created');
 $file_content = slurp($file);
-$expected_content = <<EOS;
+$expected_content = <<"EOS";
 <?xml version="1.0" encoding="UTF-8"?>
 
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
@@ -114,7 +115,7 @@ $expected_content = <<EOS;
   </url>
 </urlset>
 EOS
-is( $file_content, $expected_content, "Its content is valid" );
+is( $file_content, $expected_content, 'Its content is valid' );
 
 
 # Create a sitemap for a catalog containg 2 biblios, with option 'short url'.
@@ -128,9 +129,9 @@ $sitemapper = Koha::Sitemapper->new(
 $sitemapper->run();
 
 $file = "$dir/sitemap0001.xml";
-ok( -e $file, "File sitemap0001.xml with short URLs created");
+ok( -e $file, 'File sitemap0001.xml with short URLs created');
 $file_content = slurp($file);
-$expected_content = <<EOS;
+$expected_content = <<"EOS";
 <?xml version="1.0" encoding="UTF-8"?>
 
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
@@ -144,14 +145,16 @@ $expected_content = <<EOS;
   </url>
 </urlset>
 EOS
-is( $file_content, $expected_content, "Its content is valid" );
+is( $file_content, $expected_content, 'Its content is valid' );
 
 
 # Create a sitemap for a catalog containing 75000 biblios, with option 'short
 # url'. Test that 3 files are created: index file + 2 urls file with
 # respectively 50000 et 25000 urls.
 $data = [];
-push @$data, [ $_, '2015-08-31', '2015-08-31'] for 3..75000;
+for my $count (3..75_000) {
+    push @{$data}, [ $count, '2015-08-31', '2015-08-31'];
+}
 fixtures($data);
 $sitemapper = Koha::Sitemapper->new(
     verbose => 0,
@@ -162,9 +165,9 @@ $sitemapper = Koha::Sitemapper->new(
 $sitemapper->run();
 
 $file = "$dir/sitemapindex.xml";
-ok( -e "$dir/sitemapindex.xml", "File sitemapindex.xml for 75000 bibs created");
+ok( -e "$dir/sitemapindex.xml", 'File sitemapindex.xml for 75000 bibs created');
 $file_content = slurp($file);
-$expected_content = <<EOS;
+$expected_content = <<"EOS";
 <?xml version="1.0" encoding="UTF-8"?>
 
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@@ -179,27 +182,31 @@ $expected_content = <<EOS;
 </sitemapindex>
 EOS
 chop $expected_content;
-is( $file_content, $expected_content, "Its content is valid" );
+is( $file_content, $expected_content, 'Its content is valid' );
 
 $file = "$dir/sitemap0001.xml";
-ok( -e $file, "File sitemap0001.xml created");
+ok( -e $file, 'File sitemap0001.xml created');
 
-open my $fh, "<", $file;
+open my $fh, '<', $file or croak;
 my $count = 0;
 while (<$fh>) {
-	$count++ if /<loc>/;
+    if ($_ =~ /<loc>/xsm) { $count++; }
 }
-is( $count, 50000, "It contains 50000 URLs");
+close $fh;
+is( $count, 50_000, 'It contains 50000 URLs');
 
 $file = "$dir/sitemap0002.xml";
-ok( -e $file, "File sitemap0002.xml created");
+ok( -e $file, 'File sitemap0002.xml created');
 
-open $fh, "<", $file;
+open $fh, '<', $file or croak;
 $count = 0;
 while (<$fh>) {
-	$count++ if /<loc>/;
+    if ($_ =~ /<loc>/xsm) { $count++; }
 }
-is( $count, 25000, "It contains 25000 URLs");
+close $fh;
+is( $count, 25_000, 'It contains 25000 URLs');
 
 # Cleanup
-unlink "$dir/$_" for qw / sitemapindex.xml sitemap0001.xml sitemap0002.xml /;
+for my $file (qw/sitemapindex.xml sitemap0001.xml sitemap0002.xml/) {
+    unlink "$dir/$file";
+}
-- 
2.1.4