[Koha-patches] [PATCH] Bug 5105 - Remove use of depreciated Switch module
Colin Campbell
colin.campbell at ptfs-europe.com
Wed Sep 8 15:16:32 CEST 2010
Use of switch generates errors in perl 12 and above
Replaced uses of the Switch module by if- else constructs
Removed some mixed space+tab indentation around these where
it generated visual confusion
As of perl 10 you can use given/when constructs but this is not
supported in earlier perls.
---
C4/Reports/Guided.pm | 111 ++++++++++++++++++---------------------
basket/downloadcart.pl | 21 ++++---
opac/opac-detail.pl | 58 +++++++++-----------
opac/opac-downloadcart.pl | 29 ++++++-----
opac/opac-downloadshelf.pl | 25 +++++----
tools/batchMod.pl | 69 +++++++++++-------------
virtualshelves/downloadshelf.pl | 25 +++++----
7 files changed, 167 insertions(+), 171 deletions(-)
diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm
index 51e608b..5fb1aae 100644
--- a/C4/Reports/Guided.pm
+++ b/C4/Reports/Guided.pm
@@ -29,7 +29,6 @@ use C4::Output;
use C4::Dates;
use XML::Simple;
use XML::Dumper;
-use Switch;
use C4::Debug;
# use Smart::Comments;
# use Data::Dumper;
@@ -311,70 +310,64 @@ sub get_criteria {
my ($area,$cgi) = @_;
my $dbh = C4::Context->dbh();
my $crit = $criteria{$area};
- my $column_defs = _get_column_defs($cgi);
+ my $column_defs = _get_column_defs($cgi);
my @criteria_array;
foreach my $localcrit (@$crit) {
my ( $value, $type ) = split( /\|/, $localcrit );
my ( $table, $column ) = split( /\./, $value );
- switch ($type) {
- case 'textrange' {
- my %temp;
- $temp{'name'} = $value;
- $temp{'from'} = "from_" . $value;
- $temp{'to'} = "to_" . $value;
- $temp{'textrange'} = 1;
- $temp{'description'} = $column_defs->{$value};
- push @criteria_array, \%temp;
- }
-
- case 'date' {
- my %temp;
- $temp{'name'} = $value;
- $temp{'date'} = 1;
- $temp{'description'} = $column_defs->{$value};
- push @criteria_array, \%temp;
- }
-
- case 'daterange' {
- my %temp;
- $temp{'name'} = $value;
- $temp{'from'} = "from_" . $value;
- $temp{'to'} = "to_" . $value;
- $temp{'daterange'} = 1;
- $temp{'description'} = $column_defs->{$value};
- push @criteria_array, \%temp;
- }
-
- else {
- my $query =
- "SELECT distinct($column) as availablevalues FROM $table";
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my @values;
- # push the runtime choosing option
- my $list;
- $list='branches' if $column eq 'branchcode' or $column eq 'holdingbranch' or $column eq 'homebranch';
- $list='categorycode' if $column eq 'categorycode';
- $list='itemtype' if $column eq 'itype';
- $list='ccode' if $column eq 'ccode';
- # TODO : improve to let the librarian choose the description at runtime
- push @values, { availablevalues => "<<$column".($list?"|$list":'').">>" };
- while ( my $row = $sth->fetchrow_hashref() ) {
- push @values, $row;
- if ($row->{'availablevalues'} eq '') { $row->{'default'} = 1 };
- }
- $sth->finish();
+ if ($type eq 'textrange') {
+ my %temp;
+ $temp{'name'} = $value;
+ $temp{'from'} = "from_" . $value;
+ $temp{'to'} = "to_" . $value;
+ $temp{'textrange'} = 1;
+ $temp{'description'} = $column_defs->{$value};
+ push @criteria_array, \%temp;
+ }
+ elsif ($type eq 'date') {
+ my %temp;
+ $temp{'name'} = $value;
+ $temp{'date'} = 1;
+ $temp{'description'} = $column_defs->{$value};
+ push @criteria_array, \%temp;
+ }
+ elsif ($type eq 'daterange') {
+ my %temp;
+ $temp{'name'} = $value;
+ $temp{'from'} = "from_" . $value;
+ $temp{'to'} = "to_" . $value;
+ $temp{'daterange'} = 1;
+ $temp{'description'} = $column_defs->{$value};
+ push @criteria_array, \%temp;
+ }
+ else {
+ my $query =
+ "SELECT distinct($column) as availablevalues FROM $table";
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my @values;
+ # push the runtime choosing option
+ my $list;
+ $list='branches' if $column eq 'branchcode' or $column eq 'holdingbranch' or $column eq 'homebranch';
+ $list='categorycode' if $column eq 'categorycode';
+ $list='itemtype' if $column eq 'itype';
+ $list='ccode' if $column eq 'ccode';
+ # TODO : improve to let the librarian choose the description at runtime
+ push @values, { availablevalues => "<<$column".($list?"|$list":'').">>" };
+ while ( my $row = $sth->fetchrow_hashref() ) {
+ push @values, $row;
+ if ($row->{'availablevalues'} eq '') { $row->{'default'} = 1 };
+ }
+ $sth->finish();
- my %temp;
- $temp{'name'} = $value;
- $temp{'description'} = $column_defs->{$value};
- $temp{'values'} = \@values;
-
- push @criteria_array, \%temp;
-
- }
+ my %temp;
+ $temp{'name'} = $value;
+ $temp{'description'} = $column_defs->{$value};
+ $temp{'values'} = \@values;
+
+ push @criteria_array, \%temp;
+ }
- }
}
return ( \@criteria_array );
}
diff --git a/basket/downloadcart.pl b/basket/downloadcart.pl
index 38c6277..456f0a4 100755
--- a/basket/downloadcart.pl
+++ b/basket/downloadcart.pl
@@ -22,7 +22,6 @@ use warnings;
use CGI;
use Encode qw(encode);
-use Switch;
use C4::Auth;
use C4::Biblio;
@@ -64,16 +63,20 @@ if ($bib_list && $format) {
# Other formats
} else {
- foreach my $biblio (@bibs) {
+ foreach my $biblio (@bibs) {
- my $record = GetMarcBiblio($biblio);
+ my $record = GetMarcBiblio($biblio);
- switch ($format) {
- case "iso2709" { $output .= $record->as_usmarc(); }
- case "ris" { $output .= marc2ris($record); }
- case "bibtex" { $output .= marc2bibtex($record, $biblio); }
- }
- }
+ if ($format eq 'iso2709') {
+ $output .= $record->as_usmarc();
+ }
+ elsif ($format eq 'ris') {
+ $output .= marc2ris($record);
+ }
+ elsif ($format eq 'bibtex') {
+ $output .= marc2bibtex($record, $biblio);
+ }
+ }
}
# If it was a CSV export we change the format after the export so the file extension is fine
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index 629ebd2..b28b391 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -40,7 +40,6 @@ use C4::Serials;
use C4::Members;
use C4::VirtualShelves;
use C4::XSLT;
-use Switch;
BEGIN {
if (C4::Context->preference('BakerTaylorEnabled')) {
@@ -597,42 +596,39 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
# We try to select the best default tab to show, according to what
# the user wants, and what's available for display
my $defaulttab = '';
-switch (C4::Context->preference('opacSerialDefaultTab')) {
-
- # If the user wants subscriptions by default
- case "subscriptions" {
- # And there are subscriptions, we display them
- if ($subscriptionsnumber) {
- $defaulttab = 'subscriptions';
- } else {
- # Else, we try next option
- next;
- }
+my $deftab = C4::Context->preference('opacSerialDefaultTab');
+# If the user wants subscriptions by default
+if ($deftab eq 'subscriptions') {
+ # And there are subscriptions, we display them
+ if ($subscriptionsnumber) {
+ $defaulttab = 'subscriptions';
+ } else {
+ # Else, we try next option
+ $deftab = 'serialcollection';
}
-
- case "serialcollection" {
- if (scalar(@serialcollections) > 0) {
- $defaulttab = 'serialcollection' ;
- } else {
- next;
- }
+}
+if ($deftab eq 'serialcollection') {
+ if (scalar(@serialcollections) > 0) {
+ $defaulttab = 'serialcollection' ;
+ } else {
+ $deftab = 'holdings';
}
+}
- case "holdings" {
- if ($dat->{'count'} > 0) {
- $defaulttab = 'holdings';
- } else {
- # As this is the last option, we try other options if there are no items
- if ($subscriptionsnumber) {
- $defaulttab = 'subscriptions';
- } elsif (scalar(@serialcollections) > 0) {
- $defaulttab = 'serialcollection' ;
- }
- }
-
+if ($deftab eq 'holdings') {
+ if ($dat->{'count'} > 0) {
+ $defaulttab = 'holdings';
+ } else {
+ # As this is the last option, we try other options if there are no items
+ if ($subscriptionsnumber) {
+ $defaulttab = 'subscriptions';
+ } elsif (scalar(@serialcollections) > 0) {
+ $defaulttab = 'serialcollection' ;
+ }
}
}
+
$template->param('defaulttab' => $defaulttab);
diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl
index ff1b58f..7f2bb32 100755
--- a/opac/opac-downloadcart.pl
+++ b/opac/opac-downloadcart.pl
@@ -22,7 +22,6 @@ use warnings;
use CGI;
use Encode qw(encode);
-use Switch;
use C4::Auth;
use C4::Biblio;
@@ -61,19 +60,23 @@ if ($bib_list && $format) {
$output = marc2csv(\@bibs, $format);
- # Other formats
+ # Other formats
} else {
- foreach my $biblio (@bibs) {
-
- my $record = GetMarcBiblio($biblio);
- next unless $record;
-
- switch ($format) {
- case "iso2709" { $output .= $record->as_usmarc(); }
- case "ris" { $output .= marc2ris($record); }
- case "bibtex" { $output .= marc2bibtex($record, $biblio); }
- }
- }
+ foreach my $biblio (@bibs) {
+
+ my $record = GetMarcBiblio($biblio);
+ next unless $record;
+
+ if ($format eq 'iso2709') {
+ $output .= $record->as_usmarc();
+ }
+ elsif ($format eq 'ris') {
+ $output .= marc2ris($record);
+ }
+ elsif ($format eq 'bibtex') {
+ $output .= marc2bibtex($record, $biblio);
+ }
+ }
}
# If it was a CSV export we change the format after the export so the file extension is fine
diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl
index d73a8e7..ab1fe8d 100755
--- a/opac/opac-downloadshelf.pl
+++ b/opac/opac-downloadshelf.pl
@@ -22,7 +22,6 @@ use warnings;
use CGI;
use Encode qw(encode);
-use Switch;
use C4::Auth;
use C4::Biblio;
@@ -66,18 +65,22 @@ if ($shelfid && $format) {
# Other formats
} else {
- foreach my $biblio (@$items) {
- my $biblionumber = $biblio->{biblionumber};
+ foreach my $biblio (@$items) {
+ my $biblionumber = $biblio->{biblionumber};
- my $record = GetMarcBiblio($biblionumber);
- next unless $record;
+ my $record = GetMarcBiblio($biblionumber);
+ next unless $record;
- switch ($format) {
- case "iso2709" { $output .= $record->as_usmarc(); }
- case "ris" { $output .= marc2ris($record); }
- case "bibtex" { $output .= marc2bibtex($record, $biblionumber); }
- }
- }
+ if ($format eq 'iso2709') {
+ $output .= $record->as_usmarc();
+ }
+ elsif ($format eq 'ris' ) {
+ $output .= marc2ris($record);
+ }
+ elsif ($format eq 'bibtex') {
+ $output .= marc2bibtex($record, $biblionumber);
+ }
+ }
}
# If it was a CSV export we change the format after the export so the file extension is fine
diff --git a/tools/batchMod.pl b/tools/batchMod.pl
index f5138d1..e37ed97 100755
--- a/tools/batchMod.pl
+++ b/tools/batchMod.pl
@@ -32,7 +32,6 @@ use C4::BackgroundJob;
use C4::ClassSource;
use C4::Dates;
use C4::Debug;
-use Switch;
use MARC::File::XML;
my $input = new CGI;
@@ -164,9 +163,9 @@ if ($op eq "action") {
#-------------------------------------------------------------------------------
if ($op eq "show"){
- my $filefh = $input->upload('uploadfile');
- my $filecontent = $input->param('filecontent');
- my @notfoundbarcodes;
+ my $filefh = $input->upload('uploadfile');
+ my $filecontent = $input->param('filecontent');
+ my @notfoundbarcodes;
my @contentlist;
if ($filefh){
@@ -175,48 +174,44 @@ if ($op eq "show"){
push @contentlist, $content if $content;
}
- switch ($filecontent) {
- case "barcode_file" {
- foreach my $barcode (@contentlist) {
+ if ($filecontent eq 'barcode_file') {
+ foreach my $barcode (@contentlist) {
- my $itemnumber = GetItemnumberFromBarcode($barcode);
- if ($itemnumber) {
- push @itemnumbers,$itemnumber;
- } else {
- push @notfoundbarcodes, $barcode;
- }
- }
-
- }
-
- case "itemid_file" {
- @itemnumbers = @contentlist;
- }
- }
+ my $itemnumber = GetItemnumberFromBarcode($barcode);
+ if ($itemnumber) {
+ push @itemnumbers,$itemnumber;
+ } else {
+ push @notfoundbarcodes, $barcode;
+ }
+ }
+ }
+ elsif ( $filecontent eq 'itemid_file') {
+ @itemnumbers = @contentlist;
+ }
} else {
- if ( my $list=$input->param('barcodelist')){
- push my @barcodelist, split(/\s\n/, $list);
+ if ( my $list=$input->param('barcodelist')){
+ push my @barcodelist, split(/\s\n/, $list);
- foreach my $barcode (@barcodelist) {
+ foreach my $barcode (@barcodelist) {
- my $itemnumber = GetItemnumberFromBarcode($barcode);
- if ($itemnumber) {
- push @itemnumbers,$itemnumber;
- } else {
- push @notfoundbarcodes, $barcode;
- }
- }
+ my $itemnumber = GetItemnumberFromBarcode($barcode);
+ if ($itemnumber) {
+ push @itemnumbers,$itemnumber;
+ } else {
+ push @notfoundbarcodes, $barcode;
+ }
+ }
+ }
}
-}
# Only display the items if there are no more than 1000
if (scalar(@itemnumbers) <= 1000) {
- $items_display_hashref=BuildItemsData(@itemnumbers);
+ $items_display_hashref=BuildItemsData(@itemnumbers);
} else {
- $template->param("too_many_items" => scalar(@itemnumbers));
- # Even if we do not display the items, we need the itemnumbers
- my @itemnumbers_hashref = map {{itemnumber => $_}} @itemnumbers;
- $template->param("itemnumbers_hashref" => \@itemnumbers_hashref);
+ $template->param("too_many_items" => scalar(@itemnumbers));
+ # Even if we do not display the items, we need the itemnumbers
+ my @itemnumbers_hashref = map {{itemnumber => $_}} @itemnumbers;
+ $template->param("itemnumbers_hashref" => \@itemnumbers_hashref);
}
# now, build the item form for entering a new item
my @loop_data =();
diff --git a/virtualshelves/downloadshelf.pl b/virtualshelves/downloadshelf.pl
index 9e8de6b..253eec1 100755
--- a/virtualshelves/downloadshelf.pl
+++ b/virtualshelves/downloadshelf.pl
@@ -22,7 +22,6 @@ use warnings;
use CGI;
use Encode qw(encode);
-use Switch;
use C4::Auth;
use C4::Biblio;
@@ -65,19 +64,23 @@ if ($shelfid && $format) {
$output = marc2csv(\@biblios, $format);
# Other formats
- } else {
- foreach my $biblio (@$items) {
- my $biblionumber = $biblio->{biblionumber};
+} else {
+ foreach my $biblio (@$items) {
+ my $biblionumber = $biblio->{biblionumber};
- my $record = GetMarcBiblio($biblionumber);
+ my $record = GetMarcBiblio($biblionumber);
- switch ($format) {
- case "iso2709" { $output .= $record->as_usmarc(); }
- case "ris" { $output .= marc2ris($record); }
- case "bibtex" { $output .= marc2bibtex($record, $biblionumber); }
- }
- }
+ if ($format eq 'iso2709') {
+ $output .= $record->as_usmarc();
+ }
+ elsif ($format eq 'ris') {
+ $output .= marc2ris($record);
+ }
+ elsif ($format eq 'bibtex') {
+ $output .= marc2bibtex($record, $biblionumber);
+ }
}
+}
# If it was a CSV export we change the format after the export so the file extension is fine
$format = "csv" if ($format =~ m/^\d+$/);
--
1.7.2.2
More information about the Koha-patches
mailing list