Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/ZOOM-Perl
authorMike Taylor <mike@miketaylor.org.uk>
Thu, 16 Dec 2010 23:17:56 +0000 (23:17 +0000)
committerMike Taylor <mike@miketaylor.org.uk>
Thu, 16 Dec 2010 23:17:56 +0000 (23:17 +0000)
Changes
Makefile.PL
samples/zoom/zoom-delete-records [new file with mode: 0755]

diff --git a/Changes b/Changes
index 9a7a42a..d999f51 100644 (file)
--- a/Changes
+++ b/Changes
@@ -38,6 +38,9 @@ Revision history for Perl extension Net::Z3950::ZOOM.
          any difference to the Perl distribution.
        - Add semicolons to the commented-out sample configuration
          lines for Windows in Makefile.PL
+       - Include the useful example program
+         samples/zoom-delete-records which is installed as part of
+         "make install".
 
 1.24  Tue Jun 17 11:31:08 BST 2008
        - When Net::Z3950::ZOOM::record_get() fetches an XML record
index 79e30b2..2750492 100644 (file)
@@ -40,7 +40,8 @@ WriteMakefile(
     # OBJECT            => '$(O_FILES)', # link all the C files too
 # Use this to test for illegal code that GCC stupidly permits by default:
 #   OPTIMIZE          => "-Wdeclaration-after-statement -g -O0",
-    EXE_FILES    => [ 'samples/zoom/zselect', 'samples/zoom/zoomdump' ],
+    EXE_FILES    => [ 'samples/zoom/zselect', 'samples/zoom/zoomdump',
+                     'samples/zoom/zoom-delete-records' ],
 );
 
 
diff --git a/samples/zoom/zoom-delete-records b/samples/zoom/zoom-delete-records
new file mode 100755 (executable)
index 0000000..13c07a1
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+#
+# ./zoom-delete-records.pl user=admin,password=fruitbat,localhost:8018/IR-Explain---1 'concat(count(irspy:status/irspy:probe[@ok=1]), "/", count(irspy:status/irspy:probe))' 'count(irspy:status/irspy:probe[@ok=1]) = 0 and count(irspy:status/irspy:probe) >= 10'
+
+use lib '../lib';
+use XML::LibXML;
+use ZOOM;
+use strict;
+use warnings;
+
+die "Usage: $0 <database> <displayXPath> <deleteXPath>\n" if @ARGV != 3;
+my($dbname, $displayXPath, $deleteXPath) = @ARGV;
+
+my $libxml = new XML::LibXML;
+my $conn = new ZOOM::Connection($dbname);
+my $rs = $conn->search(new ZOOM::Query::CQL("cql.allRecords=1"));
+$rs->option(elementSetName => "zeerex");
+
+my $n = $rs->size();
+foreach my $i (1 .. $n) {
+    my $xml = $rs->record($i-1)->render();
+    my $rec = $libxml->parse_string($xml)->documentElement();
+    my $xc = XML::LibXML::XPathContext->new($rec);
+    $xc->registerNs(zeerex => "http://explain.z3950.org/dtd/2.0/");
+    $xc->registerNs(irspy => "http://indexdata.com/irspy/1.0");
+    my $val = $xc->findvalue($displayXPath);
+    print "Record $i/$n: $val";
+    $val = $xc->findvalue($deleteXPath);
+    print " DELETE" if $val eq "true";
+    print "\n";
+}