Refactor calc_reliability() down into Utils.pm, whence it is used by both full.mc...
authorMike Taylor <mike@miketaylor.org.uk>
Mon, 12 Apr 2010 11:36:02 +0000 (12:36 +0100)
committerMike Taylor <mike@miketaylor.org.uk>
Mon, 12 Apr 2010 11:36:02 +0000 (12:36 +0100)
lib/ZOOM/IRSpy/Utils.pm
web/htdocs/chrome/layout.mc
web/htdocs/details/found.mc
web/htdocs/details/full.mc

index 7853d20..9c5f951 100644 (file)
@@ -18,7 +18,8 @@ our @EXPORT_OK = qw(utf8param
                    irspy_identifier2target
                    modify_xml_document
                    bib1_access_point
-                   render_record);
+                   render_record
+                   calc_reliability);
 
 use XML::LibXML;
 use XML::LibXML::XPathContext;
@@ -770,4 +771,16 @@ sub render_record {
 }
 
 
+sub calc_reliability {
+    my($xc) = @_;
+
+    my @allpings = $xc->findnodes("i:status/i:probe");
+    my $nall = @allpings;
+    return "[untested]" if $nall == 0;
+    my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
+    my $nok = @okpings;
+    return "$nok/$nall = " . int(100*$nok/$nall) . "%";
+}
+
+
 1;
index b99cb80..1471202 100644 (file)
@@ -12,7 +12,7 @@ use ZOOM::IRSpy::Utils qw(utf8param isodate xml_encode cql_target cql_quote
                           irspy_xpath_context irspy_make_identifier
                          irspy_record2identifier
                          irspy_identifier2target modify_xml_document
-                         bib1_access_point);
+                         bib1_access_point calc_reliability);
 </%once>
 % $r->content_type("text/html; charset=utf-8");
 % my $text = $m->scomp($component, %ARGS);
index 13143c6..8380171 100644 (file)
@@ -19,22 +19,6 @@ sub navlink {
     return $url;
 }
 
-# Identical to the same-named function in full.mc
-# So maybe this should go into IRSpy::Utils.pm?
-# Name changed (append 2) to prevent inadvertent clashes in Mason namespace
-#
-sub calc_reliability2 {
-    my($xc) = @_;
-
-    my @allpings = $xc->findnodes("i:status/i:probe");
-    my $nall = @allpings;
-    return "[untested]" if $nall == 0;
-    my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
-    my $nok = @okpings;
-    return "$nok/$nall = " . int(100*$nok/$nall) . "%";
-}
-
-
 # Just make this once; forge the connection on first use
 our $conn = undef;
 </%once>
@@ -131,7 +115,7 @@ print_navlink(\%params, $last < $n, "Next", $skip+$count);
 <%perl>
 my $xc = irspy_xpath_context($rs->record($i-1));
 my $title = $xc->find("e:databaseInfo/e:title") || "[UNTITLED]";
-my $reliability = calc_reliability2($xc);
+my $reliability = calc_reliability($xc);
 my $host = $xc->find("e:serverInfo/e:host");
 my $port = $xc->find("e:serverInfo/e:port");
 my $db = $xc->find("e:serverInfo/e:database");
index abf5c01..4157b1f 100644 (file)
@@ -41,7 +41,7 @@ if ($n == 0) {
                  [ "Implementation ID" => "i:status/i:implementationId" ],
                  [ "Implementation Name" => "i:status/i:implementationName" ],
                  [ "Implementation Version" => "i:status/i:implementationVersion" ],
-                 [ "Reliability/reliability" => \&calc_reliability, $xc ],
+                 [ "Reliability/reliability" => \&calc_reliability_wrapper, $xc ],
                  [ "Services" => \&calc_init_options, $xc ],
                  [ "Bib-1 Use attributes" => \&calc_ap, $xc, "bib-1" ],
                  [ "Dan-1 Use attributes" => \&calc_ap, $xc, "dan-1" ],
@@ -95,15 +95,9 @@ if ($n == 0) {
 % }
 <%perl>
 
-sub calc_reliability {
+sub calc_reliability_wrapper {
     my($id, $xc) = @_;
-
-    my @allpings = $xc->findnodes("i:status/i:probe");
-    my $nall = @allpings;
-    return "[untested]" if $nall == 0;
-    my @okpings = $xc->findnodes('i:status/i:probe[@ok = "1"]');
-    my $nok = @okpings;
-    return "$nok/$nall = " . int(100*$nok/$nall) . "%";
+    return calc_reliability($xc);
 }
 
 sub calc_init_options {