Bug 10085: unapi does not function under Plack
authorJared Camins-Esakov <jcamins@cpbibliography.com>
Sat, 20 Apr 2013 02:52:07 +0000 (22:52 -0400)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Tue, 23 Apr 2013 12:33:51 +0000 (08:33 -0400)
The following errors appear when trying to use unapi under Plack (among
others):
Variable "$cgi" is not available at /home/jcamins/kohaclone/opac/unapi line 160.
Variable "$format_to_stylesheet_map" is not available at /home/jcamins/kohaclone/opac/unapi line 173.
Variable "$format_info" is not available at /home/jcamins/kohaclone/opac/unapi line 174.
Variable "$format_to_stylesheet_map" is not available at /home/jcamins/kohaclone/opac/unapi line 185.

To test:
1) Try to view /cgi-bin/koha/unapi under Plack
2) There is no step 2. Plack crashes.
3) Apply patch.
4) Try to view /cgi-bin/koha/unapi again, and note that it doesn't crash

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
I'm puzzled how this ever worked anyway, accidentally i'm guessing,
this tidies up some lazy coding

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
opac/unapi

index 6d8aec7..a074345 100755 (executable)
@@ -120,7 +120,7 @@ my $id     = $cgi->param('id');
 my $format = $cgi->param('format');
 
 if (not defined $format) {
-    emit_formats($id);
+    emit_formats($id, $format_to_stylesheet_map, $format_info, $cgi);
 } elsif ($id) {
 
     # koha:biblionumber:0152018484
@@ -136,7 +136,7 @@ if (not defined $format) {
                 exit 0;
             }
 
-            my $transformer = get_transformer($format);
+            my $transformer = get_transformer($format, $format_to_stylesheet_map, $format_info);
             unless (defined $transformer) {
                 print $cgi->header( -status => '406 invalid format requested' );
                 exit 0;
@@ -167,7 +167,7 @@ if (not defined $format) {
 exit 0;
 
 sub emit_formats {
-    my $id = shift;
+    my ($id, $format_to_stylesheet_map, $format_info, $cgi) = @_;
 
     if (defined $id) {
         print $cgi->header( -type =>'application/xml', -status => '300 multiple choices' );
@@ -192,7 +192,8 @@ sub emit_formats {
 
 
 sub get_transformer {
-    my $format = lc shift;
+    my ($format, $format_to_stylesheet_map, $format_info) = @_;
+    $format = lc $format;
 
     my $marcflavour = uc(C4::Context->preference('marcflavour'));
     return unless $format_to_stylesheet_map->{$marcflavour}->{$format};